Skip to content

Instantly share code, notes, and snippets.

@saniul
Created November 1, 2014 05:34
Show Gist options
  • Save saniul/d478b5537854a14e34dd to your computer and use it in GitHub Desktop.
Save saniul/d478b5537854a14e34dd to your computer and use it in GitHub Desktop.
Corrected NSHipster Raw​Option​Set​Type
struct Toppings : RawOptionSetType/*, BooleanType*/ {
var rawValue: UInt = 0
init(nilLiteral: ()) {
}
init(rawValue value: UInt) {
self.rawValue = value
}
// MARK: RawOptionSetType
static func fromMask(raw: UInt) -> Toppings {
return self(rawValue: raw)
}
// MARK: RawRepresentable
static func fromRaw(raw: UInt) -> Toppings? {
return self(rawValue: raw)
}
func toRaw() -> UInt {
return rawValue
}
// // MARK: BooleanType
//
// var boolValue: Bool {
// return rawValue != 0
// }
// MARK: BitwiseOperationsType
static var allZeros: Toppings {
return self(rawValue: 0)
}
// MARK: -
static var None: Toppings { return self(rawValue: 0b0000) }
static var ExtraCheese: Toppings { return self(rawValue: 0b0001) }
static var Pepperoni: Toppings { return self(rawValue: 0b0010) }
static var GreenPepper: Toppings { return self(rawValue: 0b0100) }
static var Pineapple: Toppings { return self(rawValue: 0b1000) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment