Search code examples
iosswiftswift3

Expected type after as


I'm developing an app which uses google location search widget to fill the location where the user was born in, but I'm getting the issue you can see right below:

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()
    }
}
            

enter image description here


Solution

  • 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