Swift中Objective-C typedef枚举的平等 [英] Equality on Objective-C typedef enum in Swift
问题描述
找不到接受提供的参数的'=='的重载
我基本上试图完成:
if state == FBSessionStateOpen {...}
我可以通过与值...
if state.value == FBSessionStateOpen.value {...}
但我想知道是否有办法使这项工作更像是一个Swift枚举?
您可以使用'.value'打开枚举和常量来获取基础整数,这应该是可切换的:
switch x.value {
case Foo.value:
}
也许这是一个错误,苹果会在将来的版本中修复它。
I'm working with the Facebook Objective-C SDK in Swift and I'm trying to compare an FBSessionState value with a value from the enum. However I get the compiler error:
Could not find an overload for '==' that accepts the supplied arguments
I'm essentially trying to accomplish:
if state == FBSessionStateOpen { ... }
I'm able to work around this by comparing against the value...
if state.value == FBSessionStateOpen.value { ... }
But I'm wondering if there is a way to make this work more like a Swift enum?
You could unwrap the enum and constants with '.value' to get the underlying integer, which should be switchable:
switch x.value {
case Foo.value:
}
Maybe this is a bug and apple fix it in future releases.
这篇关于Swift中Objective-C typedef枚举的平等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!