我正在尝试将UIUserNotificationType
的实例(RawOptionSet
)与某个值进行比较:
var types: UIUserNotificationType = ...
if types == UIUserNotificationType.None { // <-- Error here
...
}
但我在第二行遇到错误:
不明确地使用运算符'=='
关于这可能来自哪里的任何想法?
(我可以做types.toRaw() == 0
,但我认为这很难看......)
UIUserNotificationType
声明供参考:
struct UIUserNotificationType : RawOptionSet {
init(_ value: UInt)
var value: UInt
static var None: UIUserNotificationType { get }
static var Badge: UIUserNotificationType { get }
static var Sound: UIUserNotificationType { get }
static var Alert: UIUserNotificationType { get }
}
答案 0 :(得分:2)
试试这个,同时我试着看看你的错误(这个有效):
var types = UIUserNotificationType.Sound | UIUserNotificationType.Badge
switch types {
case UIUserNotificationType.None:
println("None")
case UIUserNotificationType.Badge | UIUserNotificationType.Sound :
println("Badge & Sound") // This will print
case UIUserNotificationType.Badge:
println("Badge")
case UIUserNotificationType.Alert:
println("Alert")
case UIUserNotificationType.Sound:
println("Sound")
default:
println("default")
}
这也有效,但它确实看起来像原始版本没有的错误:
if types.value == UIUserNotificationType.None.value {
println("None, too")
}