Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3.0: Type of Expression is ambiguous without more context?

private func makeRequest<T where T:MappableNetwork>(method method: Alamofire.Method, url: String,
                         parameters: [String: AnyObject]?, keyPath: String, handler: NetworkHandler<T>.handlerArray) -> Request {

    let headers = [
        "Authorization": "",
        ]

    return Alamofire
        .request(method, url, parameters: parameters, encoding: .URL, headers: headers)
        .validate()
        .responseArray(keyPath: keyPath) { (response: Alamofire.Response<[T], NSError>) in
            if let error = response.result.error {
                if let data = response.data {
                    let error = self.getError(data)
                    if error != nil {
                        handler(.Error(error: error!))
                        return
                    }
                }
                handler(.Error(error: error))
            } else if let objects = response.result.value {
                handler(.Success(data: objects))
            }
    }
}

I converted code swift 2.x to 3.x and I getting error Type expression is ambiguous without more context.

enter image description here

like image 267
Nirav Hathi Avatar asked Nov 15 '17 06:11

Nirav Hathi


1 Answers

The error you mentioned tells you that the compiler cannot determine the exact type of the value you entered.

You started with a period, something has to be before the period. Sometimes the compiler can understand without your help. That's not this case, it has several options so it's ambiguous and it asks you to tell exactly the class name that you meant.

like image 52
Yitzchak Avatar answered Nov 15 '22 03:11

Yitzchak