【发布时间】:2020-05-15 13:50:04
【问题描述】:
我得到了一个在 Objective-C 中定义的NS_OPTIONS:
typedef NS_OPTIONS(NSInteger, MyType) {
MyTypeOption1 = 1 << 0,
MyTypeOption2 = 1 << 1,
MyTypeOption3 = 1 << 2,
// etc
}
我正在将此类型导入 Swift,但我无法形成位域。
let default : MyType = MyTypeOption1 | MyTypeOption2
错误:
Protocol 'BinaryInteger' requires that 'MyType' conform to 'BinaryInteger'
IDE 表明问题出在常设冒号按位或运算符。
更改 NS_OPTIONS 声明或使用 Swift 的 OptionSet 声明新类型不是 ... 选项。如何让 Swift 打球?
【问题讨论】:
标签: objective-c swift bit-fields