4

I need to know wether navigation at start(did commit navigation) and end(ie. did finish navigation) are same or not during WkWebview's loading process.

I tried to compare WKNavigation object which the documentation states

...uniquely identify a webpage load from start to finish

WKNavigation

I either used "==" or "===" to compare two objects but never able to get match.

Is it even possible to compare WKNavigation object and if so how could I do it?

Bigair
  • 1,452
  • 3
  • 15
  • 42

1 Answers1

1

In Swift 3.2, you can use the .isEqual() method to compare two objects that conform to Equatable, as WKNavigation does.

Use-case as below:

public override func viewDidLoad() {
    super.viewDidLoad()

    // initial vc setup, including WKWebView instance
    // initialRequest is set as an instance variable for your view controller

    initialRequest = webView.load(someUrlRequest)
}

...

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    guard let navigation.isEqual(initialRequest) else { return }

    // do your finished loading logic here
}
royalmurder
  • 148
  • 1
  • 10