gpt4 book ai didi

ios - 如何在 Swift 中通过参数比较来美化枚举?

转载 作者:搜寻专家 更新时间:2023-11-01 07:28:36 25 4
gpt4 key购买 nike

这是我的

let kind = //This returns one of the cases with it corresponding arguments

if kind == .didChangeValue(value: nil) {
//my Stuff
}

这就是我想要的:

if kind == .didChangeValue {
//my Stuff
}

Notice that:

发生这种情况是因为我的枚举有参数,我已经实现了它们应该如何相互比较,而 value 对我来说没有值(value)

所以,我试图让它看起来更敏捷,而不是像RAW HACK

最佳答案

您可以使用模式匹配检查枚举值:

if case .didChangeValue = kind {
// ...
}

关于ios - 如何在 Swift 中通过参数比较来美化枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34231358/

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