Adnan Quraishi
Adnan Quraishi

Reputation: 533

Compare NSURL String and simple Swift String

I have a function in Xcode 6.2 where I want to compare a URL returned from webview and compare it with a static string. I am doing it like this:

  func webViewDidFinishLoad(webView: UIWebView){
        let currentURL = webView.request?.URL
        print("Webview did finish load ")
        println(currentURL)



        if (webView.request?.URL == "Optional(http://addi.star.com/adminpanel/first.php/login)") 
        {

        println("voilaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

        // code for dissming the view
        //self.dismissViewControllerAnimated(true, completion: nil)

        }
   }

...but it's not working. Can someone please explain how I can compare currentURL to static URL so that I can dismiss the view? I think I'm missing the types to compare it successfully, but there must be a way to do this...

Upvotes: 2

Views: 4709

Answers (2)

dopcn
dopcn

Reputation: 4218

just compare string

if (webView.request?.url?.absoluteString == "http://addi.star.com/adminpanel/first.php/login"){
    //code
}

Upvotes: 5

Muzahid
Muzahid

Reputation: 5186

 func webViewDidFinishLoad(webView: UIWebView){
            let currentURL = webView.request?.URL
            print("Webview did finish load ")
            println(currentURL)

    if let urlStr = webView?.request?.URL?.absoluteString where urlStr == "http://addi.star.com/adminpanel/first.php/login"{
        println("voilaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")

           // code for dissming the view
            //self.dismissViewControllerAnimated(true, completion: nil)

    }


        }

Hope this will help you.

Upvotes: 0

Related Questions