Ios Swift 2:@objc协议和枚举数组
我的枚举定义如下:Ios Swift 2:@objc协议和枚举数组,ios,swift,enums,swift2,protocols,Ios,Swift,Enums,Swift2,Protocols,我的枚举定义如下: @objc enum MyEnum: Int { case Case1, Case2 } 和下列议定书: @objc protocol MyProtocol { func myFunc(myData: [MyEnum]) } 现在,协议抛出以下错误: Method cannot be a member of a @objc protocol because the type of the parameter cannot be represented in
@objc enum MyEnum: Int {
case Case1, Case2
}
和下列议定书:
@objc protocol MyProtocol {
func myFunc(myData: [MyEnum])
}
现在,协议抛出以下错误:
Method cannot be a member of a @objc protocol because the type of the parameter cannot be represented in Objective-C
我不明白为什么会这样。为什么会这样:
func MyFunc(myData: MyEnum)
但是数组会抛出错误吗
我曾想过传递一个Int数组,然后将其转换回enum,但我不太喜欢它。有更好的解决方案吗?我不确定,但它不应该工作,因为Objective-C数组应该只包含指针,而
Int
的枚举不包含指针
你可以试试这样的
@objc enum MyEnum: Int {
case Case1, Case2
var numberValue : NSNumber {
get {
return NSNumber(
integer: self.rawValue
)
}
}
}
@objc protocol MyProtocol {
func myFunc(myData: [NSNumber])
}
是的,你是对的,我不认为NSArray必须只包含指针。至于解析,我将for循环移到函数外部,而不是在函数外部进行转换,然后再在函数内部进行转换