Move the Swift header import from your class's header file to the implementation file for that class, and use @class
to make a forward declaration of your Swift class.
For example, if you need to import the Swift header for a Swift class named MySwiftClass
, then before your @interface
in your header file, put the following line:
@class MySwiftClass;
That will allow your header to compile without importing the Swift header file directly. Your implementation will still need it, so that's why the import statement should be moved to the implementation file.
The same can be done if what you're trying to forward declare is a protocol. You just use the @protocol
keyword.
Using forward declarations of classes or protocols is the Objective-C way to break circular dependencies even when only Objective-C code is being used. Sometimes it's even necessary to use a forward declaration for a class or protocol defined in the same header file if for example you have a protocol and class that both refer to each other.