C Enumerations in Xcode 7.3?

I have an old Objective-C based project which I have been extending in Swift. In particular, I added to the bridging header a reference to a file containing the following declaration:


typedef enum { Read, Write, Hide } Permissions;


In Xcode 7.2, I could compare a variable of type Permissions to a constant, as in the following:


let perm = somethingThatReturnsPermissions()

if perm != Hide

{

...

}


With Xcode 7.3, I get "Use of unresolved identifier 'Hide'" on the if statement . Is there a new way to refer to C enumeration constants in Swift?


Thanks for your help.


-JCG

Maybe try using the Swift enum syntax, like this:

if perm != .Hide { ...
           ^ notice the dot, which implies `Permissions.`


No idea if this will work, but it's worth a shot. 🙂

As far as I tested (in the released version of Xcode 7.3 (7D175)), your code compiles in Swift 2.2, without problems.

I created Test.h as:

typedef enum  { Read, Write, Hide } Permissions;
extern Permissions somethingThatReturnsPermissions();

And added `#import "Test.h"` to the bridging header, then I could compile your code:

        let perm = somethingThatReturnsPermissions()
        if perm != Hide //->No errors or warnings
        {
            //...
        }


So, I'm sure Swift 2.2 can import your enum and you can use each enum label as a global constant.


But Xcode7.3/Swift 2.2 is a brand new tool and may contain various bugs. Also recent Xcodes have shown odd behaviours when upgraded or installed other versions.


You may need to try clean build, empty the build folder, or creating a freshly new project and add the files in your existing project one by one...

Anyway it's not the problem of your code shown above. Find another reason causing "Use of unresolved identifier 'Hide'".

I'm having a similar problem.


We have a complex project (discarding it and building a new one importing files one by one is something i kinda exclude) started as a pure ObjC app, and being extended in Swift. Everything went fine (it's about a month we started to work on an hybrid prj) until the members of the team upgraded to Xcode 7.3, yesterday


Noone was able to compile due to the "Use of unresolved identifier ..." problem. In our case it deals with a lot of symbols of various types. Just to make a short example it started by loosing the reference to some values coded in our constants ObjC class. These values aren't expressed as preprocessor directives (i.e. #define BAR_FOO @"something") but as follows:


In the header file (PRJConstants.h)

extern const CGFloat kStandardBarHeight;


In the compiled file (PRJConstants.m)

const CGFloat kStandardBarHeight = 50;


This ObjC class was imported into the bridging header file, and never gave a single problem, being correctly linked to the swift compiled code. Trying to solve the issue, we used the value of the connstant into the swift file using it. It started complaining about not finding other stuff. Rolled back to the first erorr generating situation, and started investigating the bridging header settings.


We are still stuck, with absolutely no clue.


Resumning our investigation experience, i can state the following:


- The project is equipped with a bridging header file

- Before upgrading from 7.2.1 to 7.3 everything was working and the cross-language usage never gave a problem

- The cross language coding is widely used and the bridging header includes a lot of import (both #import and @import directive)

- The bridging header file was (and still is) named after the <TARGET-NAME>-Bridging-Header.h convention

- We also tried the <PROJECT-NAME>-Bridging-Header.h convention

- In both cases the Objective-C Bridging Header properties in target and project build settings are correctly pointing (we double checked by mispelling them: the build failed as the file was not found)

- The bridging header file was moved to different points of the project filesystem tree, always adapting the pointing properties correctly

- The IDE allows the hypertextual navigation (⌘ + click) from the Swift file to the .m file where the constant is defined

- The IDE lost the capability to autocomplete the Header names in the Bridging Header file

- We tried to clean everything cleaneable (build folder, derived data and the project itself)

- We also tried to exclude imports punctually in order to find some error on a specific file. Nothing good happened


In addiction

- Dependencies are managed with CocoaPods. Everything was double checked and updated, but still nothing happened



We have absolutely no idea where also to look to find something to fix up.


Thanks in advance

Having the same issues with our projects. A defined Objective-C typedef is now not visible in swift. In our example, the typedef exists in header included in the bridging header:


typedef NS_ENUM(NSUInteger, MyType){

Value1 = 0,

Value2 = 1,

Value3 = 2

};

I concur, you have to define your constant outside the @interface and @end keywords.

C Enumerations in Xcode 7.3?
 
 
Q