Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C class cannot find definition for Swift protocol

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

like image 447
JAH-FH Avatar asked Mar 01 '17 20:03

JAH-FH


1 Answers

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

@interface ViewController () <MyProtocol>

@end

@implementation ViewController

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

@end
like image 125
Christopher Moore Avatar answered Oct 22 '22 23:10

Christopher Moore