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:
The forward declaration by itself didn't work for me. It compiled without errors but still had warnings that the protocol couldn't be found. I treat all warnings as errors, so this isn't good enough.
I was able to fix it by moving the protocol implementation into another category header.
So here's what worked for me:
In my MyOtherSwiftFile.swift:
@objc protocol MyProtocol: class {
func viewController(didFinishEditing viewController: MyViewController)
}
In my MyViewController.h:
@interface MyViewController // Removed protocol implementation declaration here
@end
Added MyViewController+MyProtocol.h to project, and put this in there:
@interface MyViewController (MyProtocol)
@end
The methods themselves can stay where they are if you want.
After you implement the above and compile, you'll get compiler warning(s) somewhere in your code that requires that MyViewController implements MyProtocol. In that file, you will #import "MyViewController+MyProtocol.h"