iwasrobbed/Swift-CheatSheet

The RawOptionSetType example doesn't work at all, and it's been renamed to OptionSetType

timvermeulen opened this issue · 2 comments

Something like this works:

struct Options: OptionSetType {
    let rawValue: Int

    init(rawValue: Int) {
        self.rawValue = rawValue
    }

    init(number: Int) {
        self.init(rawValue: 1 << number)
    }

    static let OptionOne = Options(number: 0)
    static let OptionTwo = Options(number: 1)
    static let OptionThree = Options(number: 2)
}

let options: Options = [.OptionOne, .OptionTwo]

options.contains(.OptionOne) // true
options.contains(.OptionThree) // false

@timvermeulen Sorry for the delay! Please feel free to open a pull request for any of these changes and I'd be happy to merge in

Will be fixed in a4f2664