I need to parse a URL string like this one:
&ad_eurl=http://www.youtube.com/video/4bL4FI1Gz6s&hl=it_IT&iv_logging_level=3&ad_flags=0&ends
If you want to do the same thing in swift, you can use an extension.
extension NSURL {
func queryDictionary() -> [String:String] {
let components = self.query?.componentsSeparatedByString("&")
var dictionary = [String:String]()
for pairs in components ?? [] {
let pair = pairs.componentsSeparatedByString("=")
if pair.count == 2 {
dictionary[pair[0]] = pair[1]
}
}
return dictionary
}
}