I have an Objective-C header that has to be used by a Swift class. However, this header has to use the Swift.h
file for an enum declared in a Swift file. In other words, the setup is as follows:
MPViewController.h
#import "MyProject-Swift.h"
@interface MPViewController: UIViewController
@property (nonatomic, assign) MPSomeEnum theEnum;
...
@end
MyProject-Bridging-Header.h
...
#import "MPViewController.h"
...
SomeEnum.swift
@objc enum MPSomeEnum: Int {
...
}
When compiling the code, I get three errors:
- 'MyProject-Swift.h' file not found
- Failed to emit precompiled header
[Xcode DerivedData folder]/[...]/MyProject-Bridging-Header-swift_[...].pch
for bridging header[Project folder]/MyProject-Bridging-Header.h
- Unknown type name 'MPSomeEnum'
Am I correct to assume that this stems from the circular reference between MyProject-Swift.h
and the bridging header MyProject-Bridging-Header.h
? From looking at a similar question one solution is to use forward declaration. However, it doesn't seem possible to forward declare an enum, so perhaps the only way to do this is to move the enum definition to an Objective-C file altogether?