swift - 如何从选项集中删除成员

标签 swift

我正在 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/

相关文章:

swift - 如何在 Swift/Cocoa 应用程序中获取 HID 设备列表?

swift - 从 appDelegate 访问 viewController 结构

iOS - [WKWebView .cxx_construct] 只能在主线程中使用

swift - 如何在调用 super.init 时捕获 self?

ios - 子类继承父类泛型的变量

swift - MKPolyLine 没有出现在 Swift 的 MapView 上

ios - NavBar 的颜色与背景颜色不同

swift - self.tabBarController?.selectedIndex 并在另一个 View Controller 中执行功能

ios - Swift:animateWithDuration 行为

ios - 我可以实时更改 UITableViewCell 的高度吗?