s-t
s-t

Reputation: 405

Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"

I saw there are many questions about Swift and Objective-C bridge including this one, this one, and this one.... But none of them helped me so far.

When adding WKNavigationDelegate and WKScriptMessageHandler, compiler fails with message "Cannot find protocol declaration".

Project-Brigding-Header.h

#import <WebKit/WebKit.h>
#include "xyz.h"

I have added WebKit.framework to Link Binary With Libraries under target > Build Phases. And made changes to build settings.

Defines Module : YES
Always Embed Swift Standard Libraries : YES
Install Objective-C Compatibility Header : YES

Do I have to do anything else to make it work?

Upvotes: 6

Views: 2644

Answers (3)

Xavier Hugo
Xavier Hugo

Reputation: 1

Just add #import <WebKit/WebKit.h> before #import "$ProjectName-Swift.h" in your Objc file. :)

Cause you cannot edit $ProjectName-Swift.h. The action imports WebKit before $ProjectName-Swift.h is imported, so the error will not appear.

Upvotes: -1

goelectric
goelectric

Reputation: 396

We had this problem too in one of our targets in the same project where other targets were building fine. We finally fixed it by adding:

#import <WebKit/WebKit.h>

To our per-compiled header file - ProjectName.pch

( thanks to https://github.com/cedarbdd/cedar/issues/397 for the clue)

It's a mystery why this solved it. We assume it was something to do with the order in which headers were being included for some mysterious reason best beknown to the Swift & Objective C compiler gurus at Apple. Would be good if Apple fixed it....

Upvotes: 0

Andrew Romanov
Andrew Romanov

Reputation: 5076

Why you are using #import <WebKit/WebKit.h> in the bridging header?
Just add in a top of swift's file:

import WebKit 

The bridging header only for application's inner classes which written with Objective-C.
WebKit is a module (in swift's term).
P.S. Also remove #import from the bridging header.

Upvotes: 2

Related Questions