我已经集成了Objective C框架以在我的Swift项目中使用。现在我的目标c框架我有一些Enum decalred alraedy
e.g.
enum LE_DEVICE_STATE
{
LE_DEVICE_STATE_DISCONNECTED=0,
LE_DEVICE_STATE_CONNECTING,
LE_DEVICE_STATE_CONNECTED,
LE_DEVICE_STATE_UPDATING_FIRMWARE
};
但现在当我尝试在切换案例中使用此枚举时,它不允许我迅速并抛出错误
“二元运算符'〜='不能应用于类型的操作数 'LE_DEVICE_STATE'和'(LE_DEVICE_STATE)'“
。所以有人可以指导我如何编写此代码?
我试图做以下
switch (theDevice.state) {
case LE_DEVICE_STATE_DISCONNECTED:
self.btnConnect.setTitle("", forState: UIControlState.Normal)
case LE_DEVICE_STATE_DISCONNECTED:
self.btnConnect.setTitle("", forState: UIControlState.Normal)
case LE_DEVICE_STATE_DISCONNECTED:
self.btnConnect.setTitle("", forState: UIControlState.Normal)
case LE_DEVICE_STATE_DISCONNECTED:
self.btnConnect.setTitle("", forState: UIControlState.Normal)
default:
self.btnConnect.setTitle("", forState: UIControlState.Normal)
}
答案 0 :(得分:3)
我想要Obj-C和Swift枚举之间的直接兼容性,那么必须使用NS_ENUM
声明Obj-C枚举。对于普通C(Obj-C)枚举,请使用.value
。