gpt4 book ai didi

Swift OptionSetType 按位或

转载 作者:行者123 更新时间:2023-11-28 12:45:19 24 4
gpt4 key购买 nike

假设我有以下 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 中包含的元素之一?

最佳答案

这个呢?

let modifier: Modifier = ...

if Modifier.Default.contains(modifier) {

}

关于Swift OptionSetType 按位或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38274203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com