🅿️OptionSet
struct ShippingOptions: OptionSet {
// ⭐️ required property
let rawValue: Int // ⭐️ conforms to 🅿️ FixedWidthInteger
}struct ShippingOptions: OptionSet {
let rawValue: Int
// ⭐️ unit sets (containing only one element)
static let nextDay = ShippingOptions(rawValue: 1 << 0)
static let secondDay = ShippingOptions(rawValue: 1 << 1)
static let priority = ShippingOptions(rawValue: 1 << 2)
static let standard = ShippingOptions(rawValue: 1 << 3)
// ⭐️ useful sets (containing multiple elements)
// ⭐️ can be initialized by array literal (ExpressibleByArrayLiteral)
static let express: ShippingOptions = [.nextDay, .secondDay]
static let all: ShippingOptions = [.express, .priority, .standard]
}
// ⭐️ empty set
let noOptions: ShippingOptions = []
Last updated