0

说我有以下OptionSetType

struct Modifier : OptionSetType {

    typealias RawValue = Int
    var rawValue: RawValue = 0

    static let Default: Modifier = [.Public, .Package, .Internal]

    static let Public    = Modifier(rawValue: 1 << 0)
    static let Package   = Modifier(rawValue: 1 << 1)
    static let Protected = Modifier(rawValue: 1 << 2)
    static let Internal  = Modifier(rawValue: 1 << 3)
    static let Private   = Modifier(rawValue: 1 << 4)

    static let Static    = Modifier(rawValue: 1 << 5) 
    static let Final     = Modifier(rawValue: 1 << 6) 

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

}

我将如何确定 type 的值是否Modifier包含至少一个包含在 中的元素Modifier.Default

4

2 回答 2

2

那这个呢?

let modifier: Modifier = ...

if Modifier.Default.contains(modifier) {

}
于 2016-07-08T19:42:07.720 回答
0
let m = Modifier()
m.contains([.Public]) // false

let m1 = Modifier.Default
m1.contains([.Public, .Package, .Internal]) // true
m1.contains([.Public])                      // true
// ....
于 2016-07-08T19:47:39.317 回答