Skip to content

Instantly share code, notes, and snippets.

@algal
Created June 17, 2015 19:18
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 algal/98da5b79539d0e0f3618 to your computer and use it in GitHub Desktop.
Save algal/98da5b79539d0e0f3618 to your computer and use it in GitHub Desktop.
Fluent interface for URLComponents
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