0
votes
typealias SwiftAMapCompletion = (CLLocation?,AMapLocationReGeocode?,Error) -> Void
var locationResult : SwiftAMapCompletion?

I want to give a nil as Error, but "Swift Compiler Error" is

Expression type 'Error' is ambiguous without more context.(SwiftAMapCompletion can't change)

locationResult!(location, reGeocode, nil as! Error)
1
typealias SwiftAMapCompletion = (CLLocation?,AMapLocationReGeocode?,Error) -> Void - KamyShi
var locationResult : SwiftAMapCompletion? - KamyShi
locationResult!(location, reGeocode, nil as! Error) - KamyShi

1 Answers

0
votes

You cannot force nil to be an Error, not even if you use as!.

Your options are:

  1. Change the declaration to be Error?, because that would mean that you can pass nil.
  2. Pass an Error.

For example:

enum MyError: Error {
    case ok
}
locationResult!(location, reGeocode, MyError.ok)

In my opinion, your SwiftAMapCompletion interface does not make any sense, because normally a callback like this would be "here is the result, or here is the error" so all parameters should be declared as optional (with ?). I would get this interface changed if you can.