This can be solved by including the Project-Swift.h
header in the implementation .m
file instead of the header file, and by using forward declarations in the header, e.g. @class SomeClass
, @protocol SomeProtocol
.
The solution is identical to the Objective-C
solution when you have two classes depending one to each-other.
For example, given the following header file:
#import "Project-Swift.h"
@interface MyObjcClass: NSObject
@property SomeSwiftClass *aProperty;
@property id<SomeSwiftProtocol> delegate;
and the .m
file like this
#import "MyObjClass.h"
@implementation MyObjcClass
...
, you need move the #import "Project-Swift.h"
into the .m file, and update your header file like this:
@class SomeSwiftClass;
@protocol SomeSwiftProtocol;
@interface MyObjcClass: NSObject
@property SomeSwiftClass *aProperty;
@property id<SomeSwiftProtocol> delegate;
@end
and the .m
file like this:
#import "Project-Swift.h"
#import "MyObjClass.h"
@implementation MyObjcClass
...
Note that you'll likely need to place the "Project-Swift.h" import before the one for your class header import if the objective-c class is declared to implement one of the Swift declared protocols.