Search code examples
swiftnsurlrequest

Swift: Cannot convert type 'NSData!' to type 'NSURLRequest!'


I'm again confronted with a strange error in Swift.

Cannot convert the expression's type 'NSData!' to type 'NSURLRequest!'

My code is:

var request = NSURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData, timeoutInterval: 5)

var response : NSURLResponse?
var error : NSError?

NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error: error)
//The error is reported at the above line

What does that mean? I nowhere try to convert NSData to NSURLRequest.


Solution

  • I am not sure why such a message is displayed but you are missing the & for inout parameters.

    NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: &error)