Xcode 7.3 beta: Undeclared Objective-C type even with bridging header

Hi everyone,


when I opened my app with xCode 7.3 beta (7D129n) I ran into several compiler issues regarding bridged data types. The app builds with xCode 7.2. I built following example which runs into the same problem: It compiles with xCode 7.2 but fails to build in xCode 7.3 beta with "Use of undeclared type 'MyType' ". Calling a method from the same class is building though.


Legacy.h:

#import <Foundation/Foundation.h>
@interface Legacy : NSObject
enum MyType : NSUInteger {
    VAL_A = 0,
    VAL_B = 1,
    VAL_C = 2,
    VAL_D = 3
};
- (void) doSomething;
@end


Legacy.m

#import <Foundation/Foundation.h>
#import "Legacy.h"
@implementation Legacy
- (void)doSomething {
    // do some stuff
}
@end


SwiftClass.swift

import Foundation
class SwiftClass {
    var legacy : Legacy = Legacy()
    var type : MyType = VAR_A // the error is: Use of undeclared type 'MyType'

    func doLegacyStuff() {
        legacy.doSomething() // creating a Legacy-object and making a call will build
    }
}


BetaProject-Bridging-Header.h

#import "Legacy.h"


Am I missing a change that was made for xCode 7.3 or is this an issue with the xCode 7.3 beta?


If more information is necessary please contact me.


Kind regards,

Alexander

Answered by guywithmazda in 108610022

You only need Legacy.h, which should contain:

#import <Foundation/Foundation.h>
enum MyType : NSUInteger { 
    VAL_A = 0,
    VAL_B = 1,
    VAL_C = 2,
    VAL_D = 3
};

and your bridging header.


EDIT: Not sure why it works the other way in 7.2, but this way seems to work in both.

Accepted Answer

You only need Legacy.h, which should contain:

#import <Foundation/Foundation.h>
enum MyType : NSUInteger { 
    VAL_A = 0,
    VAL_B = 1,
    VAL_C = 2,
    VAL_D = 3
};

and your bridging header.


EDIT: Not sure why it works the other way in 7.2, but this way seems to work in both.

Sorry, deleting the Legacy.m won't do it. Even with header file only it still produces the error "Use of undeclared type 'MyType' ".


I added the implementation file, because in our app there are actually method definitions and their implementation in these files.

You have to modify the .h file as I showed, moving the enum outside the interface. It should still work even with an implemenation.

Ah sorry, I missed that point. Thank you, that will work with the implementation, too.

Xcode 7.3 beta: Undeclared Objective-C type even with bridging header
 
 
Q