3
用下面OptionSet:雨燕3.0 OptionSet位測試
struct StatusOptions : OptionSet {
let rawValue: Int
static let CountdownDuration0 = StatusOptions(rawValue: 1 << 0)
static let CountdownDuration1 = StatusOptions(rawValue: 1 << 1)
static let CountdownDuration2 = StatusOptions(rawValue: 1 << 2)
static let CountdownDuration3 = StatusOptions(rawValue: 1 << 3)
static let CountdownDuration4 = StatusOptions(rawValue: 1 << 4)
static let CountdownDuration5 = StatusOptions(rawValue: 1 << 5)
static let HomeMode = StatusOptions(rawValue: 1 << 6)
static let AwayMode = StatusOptions(rawValue: 1 << 7)
static let Disarmed: StatusOptions = []
static let ArmedHome: StatusOptions = .HomeMode
static let ArmedAway: StatusOptions = .AwayMode
static let ArmedBoth: StatusOptions = [.HomeMode, .AwayMode]
static let ArmingCountdown: StatusOptions = [.CountdownDuration0, .CountdownDuration1, .CountdownDuration2, .CountdownDuration3, .CountdownDuration4, .CountdownDuration5]
}
如何比較字節
var statusFlags: UInt8 = 0b00000000
到選項?
下面是什麼,我會想會的工作,但會導致一個操場錯誤:
if (statusFlags & .Disarmed) {
print("Disarmed")
}
感謝