Swift Language
OptionSet
수색…
OptionSet 프로토콜
OptionSetType은 개별 비트가 집합의 멤버를 나타내는 비트 마스크 유형을 나타내도록 설계된 프로토콜입니다. 논리 및 / 또는 함수 집합은 적절한 구문을 시행합니다.
struct Features : OptionSet {
let rawValue : Int
static let none = Features(rawValue: 0)
static let feature0 = Features(rawValue: 1 << 0)
static let feature1 = Features(rawValue: 1 << 1)
static let feature2 = Features(rawValue: 1 << 2)
static let feature3 = Features(rawValue: 1 << 3)
static let feature4 = Features(rawValue: 1 << 4)
static let feature5 = Features(rawValue: 1 << 5)
static let all: Features = [feature0, feature1, feature2, feature3, feature4, feature5]
}
Features.feature1.rawValue //2
Features.all.rawValue //63
var options: Features = [.feature1, .feature2, .feature3]
options.contains(.feature1) //true
options.contains(.feature4) //false
options.insert(.feature4)
options.contains(.feature4) //true
var otherOptions : Features = [.feature1, .feature5]
options.contains(.feature5) //false
options.formUnion(otherOptions)
options.contains(.feature5) //true
options.remove(.feature5)
options.contains(.feature5) //false
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow