从升级到Xcode 7.3 swift 2.2后,从swift调用obj-c枚举不起作用 [英] Calling obj-c enum from swift not working after upgrading to Xcode 7.3 swift 2.2

查看:121
本文介绍了从升级到Xcode 7.3 swift 2.2后,从swift调用obj-c枚举不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码在升级到7.1之前的Xcode 7.3和swift 2.2之前工作得很好。我也看过使用typedef NS_ENUM(NSUInteger,MyStatus)...的答案...但是如果可能,我不想更改现有的obj-c代码

The code was working well before the upgrade to Xcode 7.3 from 7.1 and swift 2.2. I have also seen answers using the typedef NS_ENUM(NSUInteger, MyStatus)... but if possible, I prefer not to change the existing obj-c code.

在obj-c头文件中定义:

Defined in obj-c header file:

typedef enum {
    StatusPending,
    StatusTimeout,
    StatusSuccess,
    StatusFail
} MyStatus;

Swift文件中的声明:

Statement in Swift file:

/* some code to retrieve the status */

switch (status) {

case .StatusSuccess:
 /* do something */

/* other test cases omitted here */

default:

}

我尝试使用.rawValue,.value等,但我仍然收到错误:

I've tried using .rawValue, .value, etc, but I still get an error:

在MyStatus类型中未找到枚举大小写StatusSuccess

Enum case 'StatusSuccess' not found in type 'MyStatus'

在升级之前所有工作正常,并尝试卸载/重新安装Xcode 7.3,Product-> Clean ,Product-> Clean Build Folder ..但没有成功: - (

All was working fine before the upgrade and have tried uninstalling/reinstalling Xcode 7.3, Product->Clean, Product->Clean Build Folder.. but without success :-(

推荐答案

你不能声明typedef NS_ENUM(NSUInteger ,EnumName){}在@interface和@end中,xcode 7.2的解析与xcode 7.3不同,所以只需在@interface @end块之外移动你的枚举声明,它应该可以正常工作,否则它被认为是私有声明

You can't declare "typedef NS_ENUM (NSUInteger, EnumName){}" within @interface and @end, the parsing of xcode 7.2 is different from xcode 7.3. So, just move your enum declarations outside @interface @end block and it should work fine, otherwise its considered a private declaration

这篇关于从升级到Xcode 7.3 swift 2.2后,从swift调用obj-c枚举不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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