How to prevent circular reference when Swift bridging header imports a file that imports Hopscotch-Swift.h itself

Forward declaration should work, in your case.

In your .h:

@protocol MyProtocol;

@interface MyController : UIViewController<MyProtocol>

@end

In your .m:

#import "HopScotch-Swift.h"

From How can I add forward class references used in the -Swift.h header? and the Swift interoperability guide:

If you use your own Objective-C types in your Swift code, make sure to import the Objective-C headers for those types prior to importing the Swift generated header into the Objective-C .m file you want to access the Swift code from.

Leave a Comment