我正在 Xcode 8 的 iOS Playground 中尝试此操作,但它不起作用:
struct Direction: OptionSet {
let rawValue: UInt8
static let none = Direction(rawValue: 0)
static let up = Direction(rawValue: 1 << 0)
static let left = Direction(rawValue: 1 << 1)
static let down = Direction(rawValue: 1 << 2)
static let right = Direction(rawValue: 1 << 3)
static let all = [up, left, down, right]
}
var directions = Direction.all
directions.remove(.up) // Error: Missing argument label 'at:' in call
Apple's documentation表明我应该能够
"...to add or remove members from an instance of your custom option set type."
文档引用了 remove()
函数,但这不起作用。我做错了什么?
最佳答案
尝试更改 all
的声明:
static let all: Direction = [.up, .left, .down, .right]
关于swift - 如何从选项集中删除成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428095/