Swift中Objective-C typedef枚举的平等 [英] Equality on Objective-C typedef enum in Swift

查看:100
本文介绍了Swift中Objective-C typedef枚举的平等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift的Facebook Objective-C SDK,我试图将FBSessionState值与枚举值进行比较。但是我得到编译器错误:


找不到接受提供的参数的'=='的重载


我基本上试图完成:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆