Giter VIP home page Giter VIP logo

Comments (7)

mkanthan avatar mkanthan commented on August 17, 2024 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.

akitchen avatar akitchen commented on August 17, 2024

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
...
@EnD

On 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.

mkanthan avatar mkanthan commented on August 17, 2024

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.

akitchen avatar akitchen commented on August 17, 2024

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.

PoppyMan avatar PoppyMan commented on August 17, 2024

I and you the same, I finally know how to solve, thank you very much!!!!!!

from cedar.

Gamshan avatar Gamshan commented on August 17, 2024

I am also struggle in same thing @mkanthan answer help me. thankyou

from cedar.

sashaweiss avatar sashaweiss commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.