【问题标题】:Using an enum from objective-c in swift class在 swift 类中使用来自 Objective-c 的枚举
【发布时间】:2015-02-02 15:46:51
【问题描述】:

我在objective-c中有一个枚举

typedef enum {
status1,
status2,
} BattStatus;
@property (nonatomic) BattStatus batStatus;

要快速使用它,我正在做:

switch (MySingleton.sharedInstance().batStatus){
    case status1: break
    case status2: break
    default: break
} 

它给了我错误:BattStatus does not conforms to protocol 'IntervalType'。在线case status1: break

我还不能编辑第一个objective-c Singleton 类。暂时只能使用它。

【问题讨论】:

    标签: objective-c swift enums


    【解决方案1】:

    Objective-C enum 声明仅在使用 NS_ENUM 宏时作为 Swift enums 导入。您需要在任何 BattStatus 实例上使用 value 属性来访问其值以进行比较。

    您可以在此处阅读更多内容:C-Style "typedef enum" in Swift

    【讨论】:

    • 谢天谢地,必须编辑 obj-c 单例,所以我没有测试它,但你的意思是我必须这样做:status1.value
    • status1.value...batStatus.value。实例本身不可比较。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多