Could somone answer a quick question. I'm reading "IOS Apps with REST" where the auther discusses using a Router object to create requests with Alamofire. (code included below). My question is what is this. what is the (encoded, _) part of the this line "let (encoded, _) = encoding.encode(URLRequest, parameters: result.parameters)" Is that supposed to be a tuple and the second arg just isn't ever used thus it has no name.
Thanks
Dave.
// Sample router.
enum Router: URLRequestConvertible
{
static let baseURLString = "http://jsonplaceholder.typicode.com/"
case Get(Int)
case Create([String: AnyObject])
case Delete(Int)
var URLRequest: NSMutableURLRequest
{
var method: Alamofire.Method
{
switch self
{
case .Get:
return .GET
case .Create:
return .POST
case .Delete:
return .DELETE
}
}
// constant result that returns a tuple. you can pic result.path or result.parameters
let result: (path: String, parameters: [String: AnyObject]?) = {
switch self {
case .Get(let postNumber):
return ("posts/\(postNumber)", nil)
case .Create(let newPost):
return ("posts", newPost)
case .Delete(let postNumber):
return ("posts/\(postNumber)", nil)
}
}()
let URL = NSURL(string: Router.baseURLString)!
let URLRequest = NSURLRequest(URL: URL.URLByAppendingPathComponent(result.path))
let encoding = Alamofire.ParameterEncoding.JSON
let (encoded, _) = encoding.encode(URLRequest, parameters: result.parameters)
encoded.HTTPMethod = method.rawValue
return encoded
}
}