vendredi 30 janvier 2015

SWIFT IOS return 2 different objects in a same function

I want to return request if all went well and return error if something went wrong.



func afnwPost(url: String,client_id: String, client_secret:String,grant_type:String, userparam: String, passwordparam:String)-> AnyObject{

var parameters = ["client_id":client_id,"client_secret":client_secret,"grant_type":grant_type,"username":userparam,"password":passwordparam]

manager.POST( url,
parameters: parameters,
success: { (operation: AFHTTPRequestOperation!,responseObject: AnyObject!) in
println("JSON: " + responseObject.description)
return responseObject
},
failure: { (operation: AFHTTPRequestOperation!,error: NSError!) in
println("Error: " + error.localizedDescription)
return error
})
}


The call method



var respuesta = obtenerToken.afnwPost(host_oauth,
client_id: client_id,
client_secret:client_secret,
grant_type:grant_type_token,
userparam: textfieldUsuario.text,
passwordparam: textfieldContrasenya.text)



Aucun commentaire:

Enregistrer un commentaire