Santosh Santosh - 4 months ago 167
Swift Question

Swift : expected type after as , Xcode 8-Beta, Swift 3

This this code Where I'm getting the error..
This this code Where I'm getting the error..
This this code Where I'm getting the error..
This this code Where I'm getting the error..
This this code Where I'm getting the error..

[![private class func doRequest(_ urlString: String, params: \[String: String\], success: (NSDictionary) -> ()) {
if let url = URL(string: "\(urlString)?\(query(params))"){

let request = NSMutableURLRequest(
url:url
)

let session = URLSession.shared()
let task = session.dataTask(with: request) { data, response, error in
self.handleResponse(data, response: response as?, error: error, success: success)
}

task.resume()
}
}][1]][1]


enter image description here

Answer

as? is use to cast one type to another, you are asking Xcode to cast response to another type, but haven't told it what to cast it to.

As the error says, its expecting to see a type after the keyword as