Comments (7)
@akitchen I fixed this issue - it seems I was missing an import in Specs-Prefix.pch. I added this line to Specs-Prefix.pch:
#import <WebKit/WebKit.h>
I think I can consider this issue closed. However, it's a bit of a mystery to me why it wasn't until I introduced the delegate that it stopped compiling. It was fine with WKWebView which is another WebKit framework class.
from cedar.
How is your WKNavigationDelegate declared? And if it is in an ObjC header,
is it in a header search path which is visible within this project target?
On Mon, Sep 12, 2016 at 9:56 AM, Manu Kanthan [email protected]
wrote:
I'm running into a compilation error when introducing a
WKNavigationDelegate into my view controller.My project config: I'm using Cedar in the "stand-alone" setup, with a
separate Specs target. I have not been able to get Swift specs working
properly (although this is probably a different issue). However, I can
write Objective-C specs for Swift modules. So for now, my Spec files are
all in Objective-C, and my main target is a mix of Swift and Objective-C
which compiles and runs fine (with the correct bridging headers). I should
add that my project is an older project started with Cedar/Objective-C from
a while ago, so I'm not sure if there's other config that I'm lacking. I'm
running Cedar 0.13.1.Everything compiles and runs fine when my code is the following:
MyViewController.swift:
import Foundation
class MyViewController: UIViewController {
var webView: WKWebView!override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.displayWKViewContent() } func displayWKViewContent() -> Void { let baseURLForRequest = kAccountsURL let url = NSURL(string: baseURLForRequest) let request = NSURLRequest(URL: url!) webView = WKWebView(frame: self.view.frame) webView.loadRequest(request) webView.frame = CGRect(origin: CGPoint(x: 43, y: 44), size: CGSize(width: 938, height: 680)) self.view.addSubview(webView) self.view.sendSubviewToBack(webView) }
}
MyViewControllerSpec.mm:
#import <My_App-Swift.h>
#import <WebKit/WebKit.h>using namespace Cedar::Matchers;
using namespace Cedar::Doubles;SPEC_BEGIN(MyViewController)
fdescribe(@"MyViewController", ^{
__block MyViewController * wkController = nil;
__block WKWebView * webView = nil;beforeEach(^{ wkController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]; [wkController view]; webView = wkController.webView; }); it(@"should have a WKWebView assigned to the webView", ^{ expect(webView).to(be_instance_of([WKWebView class])); });
});
SPEC_END
Things start to go awry when I introduce the WKNavigationDelegate:
class MyViewController: UIViewController, WKNavigationDelegate {
...
}Running my Specs target, I get a compiler error inside my auto-generated
Swift header (My_App-Swift.h):SWIFT_CLASS("_TtC24My_App25MyViewController")
@interface MyViewController : UIViewController
...
@EnDOn this line, I get the compiler error Cannot find protocol declaration
for 'WKNavigationDelegate'; did you mean 'UINavigationBarDelegate'?.
Obviously, I didn't mean UINavigationBarDelegate. But I'm not sure what I'm
missing - I've done the necessary imports of UIKit, and WebKit in the Spec
file, as well as the bridging header.FYI, my main target compiles and runs fine, and I'm able to set up the
delegate, etc. I'm stumped here.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#397, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAXHGNsM-RUPeom7zIBvKeoQ7iJaExzvks5qpYQkgaJpZM4J6zKS
.
from cedar.
I've declared it on MyViewController - MyViewController.swift (same file I posted above). It is not in an Objective-C header anywhere.
So, declaring it and running my main app target with the following compiles and runs fine (displays the log message some time after I execute loadRequest
on the WKWebView):
import Foundation
class MyViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
...
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.displayWKViewContent()
}
func displayWKViewContent() -> Void {
...
webView.navigationDelegate = self
...
}
func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
NSLog("WKWebView started to load.")
}
}
However, with this same code, my Specs target does not even compile and gives me an error in my autogenerated -Swift.h file. If I were to remove the WKNavigationDelegate
and the delegate method, the Specs target compiles and runs.
In case you want to see my bridging header (Specs-Bridging-Header.h), it's here:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "NSString+URLQueryParsing.h"
#import "WebViewStrings.h"
#import "UIKit/UIKit.h"
#import "WebKit/WebKit.h"
Importing WebKit.h here should be enough, correct?
Edit: Forgot to add that I set the delegate in displayWKViewContent()
.
from cedar.
Thank you for the update! Glad to hear you got things resolved.
I wonder if this had anything to do with the ancestry of your protocol declaration. We have definitely seen weird quirks around protocol loading/discovery in the past.
On Sep 13, 2016, at 12:34, Manu Kanthan [email protected] wrote:
@akitchen I fixed this issue - it seems I was missing an import in Specs-Prefix.pch. I added this line to Specs-Prefix.pch:
#import <WebKit/WebKit.h>
I think I can consider this issue closed. However, it's a bit of a mystery to me why it wasn't until I introduced the delegate that it stopped compiling. It was fine with WKWebView which is another WebKit framework class.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
from cedar.
I and you the same, I finally know how to solve, thank you very much!!!!!!
from cedar.
I am also struggle in same thing @mkanthan answer help me. thankyou
from cedar.
I'm having a similar issue (not with Cedar specifically, but re: protocols not being found). Has anyone found anything more about the underlying issue, e.g. why importing to the prefix header helped?
Specifically, I'm trying to use a Swift protocol (declared in a Development Pod) on a Swift class (in my main project, which is mixed ObjC and Swift). I get the same issue as above, where in the <ProjectName>-Swift.h
file the protocol declaration cannot be found. Swift classes I use from that Pod seem to be fine - at least, the <ProjectName>-Swift.h
header forward declares them so it compiles ok.
Thanks in advance if anyone has pointers!
from cedar.
Related Issues (20)
- Console output is logged out of order HOT 1
- new project can't find cedar HOT 1
- Xcode 7.3 beta 5 errors on __weak in manual reference counting HOT 6
- Use of @import HOT 2
- Custom matchers fails to compile using Xcode 7.3 HOT 4
- Test observation issues HOT 2
- Weak References in XCode 7.3 HOT 4
- Playground support
- Installing template fails on AppCode 2016.1 HOT 1
- Cedar silently accepts misuse of the test structure DSL
- Running Individual Specs HOT 9
- testing watchOS with Cedar and Swift
- Cedar Standalone with XCode 8/ios-sim 5.0.8 HOT 4
- Cedar needs a sticker. HOT 4
- should equal throws exception when comparing const pointer to a non-const pointer HOT 5
- Cedar status HOT 1
- Xcode 9 compatibility HOT 8
- [Known Issue] Cedar's test specs cannot be folded in Xcode 9
- spy_on NSDate crashes on Xcode 10 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cedar.