Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting query string parameters from url in the UIWebView in Swift?

my question is pretty straight forward. Can someone please show me how to get the query string parameters in a url received by the UIWebView. It is pretty easy in objective c, but I need some help in swift as i'm new to the language. Thanks in advance.

like image 493
Lakmal Caldera Avatar asked Oct 20 '14 10:10

Lakmal Caldera


1 Answers

In the NSURL class exists the .query property which returns the string of everything after the ? in the url in form: http://www.example.com/index.php?key1=value1&key2=value2 in this example using the code:

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

More information in the documentation

As far as getting the url from the uiwebview, you could use something along the lines of:

let url: NSURL = someWebView.NSURLRequest.URL
like image 95
Ian Avatar answered Sep 28 '22 04:09

Ian