6
I have the following code when I want to make a call to the server:
let mutableURLRequest = NSMutableURLRequest(url: URL)
mutableURLRequest.httpMethod = "POST"
let parameters = ["SessionID": sessionID]
do {
mutableURLRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: JSONSerialization.WritingOptions())
} catch {}
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(**mutableURLRequest**).responseJSON{
response in if let JSON = response.result.value{}}
Where the text is BOLD is giving me error in this variable
Argument type 'NSMutableURLRequest' does not conform to expected type 'URLRequestConvertible'
yet you give me the following option
Fix-it Insert as! URLRequestConvertible
If I accept the suggestion is put in the code what they say but the error persists and tells to put again and is this infinitely.
Does anyone know how to solve this problem?
Just a suggestion. Do you only use the Alamofire for basic orders? Because if that’s the case, the basic use of Urlsession would be sufficient instead of walking with a dependency as large as the Alamofire.
– Nuno Gonçalves
@Nunogonçalves, yes I only use the Alamofire for basic orders, I am new to programming in Io and at the time I tried many ways to order from the server and I did not succeed with any. Until finally with Alamofire gave soon. Can you post or give an example of Urlsession? Thanks
– HideCode
I added an answer with an example that can be pasted directly onto a playground.
– Nuno Gonçalves