说我有以下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
}
}
如何确定Modifier
类型的值是否包含Modifier.Default
中包含的至少一个元素?
答案 0 :(得分:2)
这个怎么样?
let modifier: Modifier = ...
if Modifier.Default.contains(modifier) {
}
答案 1 :(得分:0)
let m = Modifier()
m.contains([.Public]) // false
let m1 = Modifier.Default
m1.contains([.Public, .Package, .Internal]) // true
m1.contains([.Public]) // true
// ....