Im in a situation where I need to use Objective-C category to extend a Swift class. I've done something as follows:
In "SomeClass.swift":
class SomeClass: NSObject {
}
In "SomeClass+Extension.h":
#import "Project-Swift.h"
@interface SomeClass (Extension)
-(void)someMethod();
@end
This has worked well. And if I try to use the SomeClass extension in my Objective C code, it is fine.
The problem is, if I want to use someMethod()
in a another Swift class, I will need to put the SomeClass+Extension.h
file into my ObjC-BridgingHeader.h
file.
But doing this will cause a circular dependency, because SomeClass+Extension.h
also imports Project-Swift.h
.
Does anyone have a good way to get around this?
Please note that simply forward declaring the class in the category header will not work, as categories cannot use forward declarations for it's own implementation as so:
@class SomeClass
without importing Project-Swift.h
will give a compile error.
class undefined error
. So unforunately your solution will not work. – stephen