从Swift的UIWebView中的url获取查询字符串参数?

Lak*_*era 4 uiwebview ios swift ios8

我的问题很简单.有人可以告诉我如何在UIWebView收到的URL中获取查询字符串参数.在目标c中它很容易,但我需要一些快速的帮助,因为我是这门语言的新手.提前致谢.

Ian*_*Ian 10

在NSURL类中存在的.query属性返回后的所有内容的字符串?在url中的形式:http://www.example.com/index.php? key1 = value1&key2 = value2 在此示例中使用代码:

var url: NSURL = NSURL(string: "http://www.example.com/index.php?key1=value1&key2=value2")
println(url.query) // Prints: Optional("key1=value1&key2=value2")
Run Code Online (Sandbox Code Playgroud)

文档中的更多信息

从uiwebview获取网址,你可以使用以下内容:

let url: NSURL = someWebView.NSURLRequest.URL
Run Code Online (Sandbox Code Playgroud)