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