9
votes

I have a Swift protocol, like so:

@objc protocol Linkable {
    func presentLink(link: MyLink)
}

I also have an Objective-C class that isn't playing nice with this protocol:

@protocol Linkable;

@interface MyDetailViewController : MyTableViewController <Linkable>

etc...

I have declared the protocol correctly as far as I can tell, the protocol has the @objc notation, and I'm putting it into the interface declaration of the Objective C class, but I'm still getting a warning at the line that starts @interface.

The warning says: "Cannot find protocol definition for 'Linkable'."

Oddly, it builds and runs, and it works as expected, but why the warning if there's actually no problem with Linkable? Is there a different way to declare the protocol, or to conform to it that would clear the warning?

Is this just one of Xcode's warnings that is poorly phrased, and if so what's actually going on?

EDIT

Here is a self-contained sample project with the same error: https://github.com/thinkfishhook/Swift-ObjC_Protocol

1
Do you #import "<YourProjectName>-Swift.h" in MyDetailViewController.m? - Martin R
I do, yes: #import "MyApp-Swift.h" - JAH-FH
@MartinR - I have edited the post to add a repo with a small standalone project that has the warning. Thanks so much for your help! - JAH-FH
I think you need to move your bridging header import to the header file where you are using it instead of the implementation file. - Christopher Moore
@ChristopherMoore You can't have the bridging header in the .h file. Xcode says it doesn't exist if imported into .h. It only works for .m files. - nickdnk

1 Answers

1
votes
#import "ViewController.h"
#import "Protocol_WTF-Swift.h"

@interface ViewController () <MyProtocol>

@end

@implementation ViewController

- (void)doTheThings {
  // doing the things
}

@end