Created
April 23, 2016 20:56
-
-
Save Gujci/0f6cbcab4257b78c0643de571e7931fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSURL { | |
convenience init(string: String, query: Dictionary<String, String>?) { | |
if query == nil { | |
self.init(string: string)! | |
return | |
} | |
let components = NSURLComponents(string: string) | |
var querryItems = components?.queryItems ?? Array<NSURLQueryItem>() | |
query?.forEach() { | |
querryItems.append(NSURLQueryItem(name: $0.0, value: $0.1)) | |
} | |
components?.queryItems = querryItems | |
self.init(string: "",relativeToURL: components!.URL)! | |
} | |
convenience init(url: NSURL, query: Dictionary<String, String>?) { | |
let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: false) | |
var querryItems = components?.queryItems ?? Array<NSURLQueryItem>() | |
query?.forEach() { | |
querryItems.append(NSURLQueryItem(name: $0.0, value: $0.1)) | |
} | |
components?.queryItems = querryItems | |
self.init(string: "",relativeToURL: components!.URL)! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment