比较 NSURL 字符串和简单 Swift 字符串

Compare NSURL String and simple Swift String

我在 Xcode 6.2 中有一个函数,我想比较从 webview 返回的 URL 并将其与静态字符串进行比较。我是这样做的:

  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)

        }
   }

...但它不起作用。有人可以解释一下我如何比较 currentURL 和 static URL 以便我可以忽略视图吗?我想我缺少成功比较它的类型,但必须有办法做到这一点...

 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)

    }


        }

希望对您有所帮助。

只是比较字符串

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