1
位移位OptionSet ...移位OptionSet是7的倍数?斯威夫特3
struct VerifiedOptions : OptionSet {
let rawValue: Int
static let facebook = VerifiedOptions(rawValue: 1 << 0)
static let email = VerifiedOptions(rawValue: 1 << 1)
static let phoneNumber = VerifiedOptions(rawValue: 1 << 2)
static let count:Int = 3
}
使用这样的...
let options:VerifiedOptions = [.facebook,.email,.phoneNumber]
for i in 0..<VerifiedOptions.count {
let option = VerifiedOptions(rawValue: options.rawValue << i)
print("O:",option.rawValue,"T:",options.rawValue)
if options.contains(option) { print("match") }
}
打印解决的
O:7 T:7
match
O:14 T:7
O:28 T:7
两个问题... 。
- 为什么位移的倍数是7而不是1的倍数?
- 为什么不是
options
显示内部有3个选项?
谢谢你的时间。
你应该使用'for我在options.indication {...' – Alexander
有趣的,我会研究。谢谢 – Magoo