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

前端 未结 4 1862
栀梦
栀梦 2020-11-27 15:33

I am integrating Swift into a large existing Objective C project and have run into what I think is a circular reference.

The classes in question are as follows:

4条回答
  •  醉酒成梦
    2020-11-27 16:28

    Forward declaration should work, in your case.

    In your .h:

    @protocol MyProtocol;
    
    @interface MyController : UIViewController
    
    @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.

提交回复
热议问题