Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling obj-c enum from swift not working after upgrading to Xcode 7.3 swift 2.2

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.

Defined in obj-c header file:

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

Statement in Swift file:

/* some code to retrieve the status */

switch (status) {

case .StatusSuccess:
 /* do something */

/* other test cases omitted here */

default:

}

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

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

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

like image 650
craman Avatar asked Mar 24 '16 08:03

craman


1 Answers

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

like image 81
Kunal Khanna Avatar answered Oct 19 '22 21:10

Kunal Khanna