Skip to content

Instantly share code, notes, and snippets.

@Limon-O-O
Last active November 23, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Limon-O-O/bae6b3a92e91996faab8 to your computer and use it in GitHub Desktop.
Save Limon-O-O/bae6b3a92e91996faab8 to your computer and use it in GitHub Desktop.
Extension to access the URL Parameters within your NSURL.

Producter Tips

extension NSURL {
    var prt_URLItems: [String: String]? {

        let components = NSURLComponents(URL: self, resolvingAgainstBaseURL: false)

        guard let items = components?.queryItems else {
            return nil
        }

        var infos = [String: String]()
        items.forEach {
            infos[$0.name] = $0.value
        }
        return infos
    }
}
let items = NSURL(string: "http://www.weibo.com/1783821582/profile?rightmod=1&wvr=6&mod=personinfo")?.prt_URLItems
print(items)

// Optional(["mod": "personinfo", "rightmod": "1", "wvr": "6"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment