Created
June 17, 2015 19:18
-
-
Save algal/98da5b79539d0e0f3618 to your computer and use it in GitHub Desktop.
Fluent interface for URLComponents
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
private extension NSURLComponents | |
{ | |
func withQueryItem(name:String,intValue:Int) -> NSURLComponents { | |
return self.withQueryItem(name, stringValue: NSNumber(integer: intValue).stringValue) | |
} | |
func withQueryItem(name:String,floatValue:Float) -> NSURLComponents { | |
return self.withQueryItem(name, stringValue: NSNumber(float: floatValue).stringValue) | |
} | |
func withQueryItem(name:String,stringValue:String) -> NSURLComponents { | |
let newQueryItem = NSURLQueryItem(name:name,value:stringValue) | |
let existingItems = self.queryItems ?? [] | |
self.queryItems = existingItems + [newQueryItem] | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment