相关疑难解决方法(0)

你如何在Swift中枚举OptionSetType?

我在Swift中有一个自定义的OptionSetType结构.如何枚举实例的所有值?

这是我的OptionSetType:

struct WeekdaySet: OptionSetType {
    let rawValue: UInt8

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

    static let Sunday        = WeekdaySet(rawValue: 1 << 0)
    static let Monday        = WeekdaySet(rawValue: 1 << 1)
    static let Tuesday       = WeekdaySet(rawValue: 1 << 2)
    static let Wednesday     = WeekdaySet(rawValue: 1 << 3)
    static let Thursday      = WeekdaySet(rawValue: 1 << 4)
    static let Friday        = WeekdaySet(rawValue: 1 << 5)
    static let Saturday      = WeekdaySet(rawValue: 1 << 6)
}
Run Code Online (Sandbox Code Playgroud)

我想这样的事情:

let weekdays: WeekdaySet = [.Monday, .Tuesday] …
Run Code Online (Sandbox Code Playgroud)

swift swift2 swift3

33
推荐指数
2
解决办法
6352
查看次数

标签 统计

swift ×1

swift2 ×1

swift3 ×1