I have a function that accepts a request and an optional callback for a server response:
static func getData(request: NSMutableDictionary?, callback: ((Dictionary<String, Any>) -> Void)? ) {
// ...
}
I want to write a wrapper over this function in which the parameters are not optional. I did it like this:
static func getData(id: CLong, callback: ((Dictionary<String, Any>) -> Void) ) {
getData(request: ["userId" : id], callback: callback)
}
The problem is that swift cannot convert type ((Dictionary<String, Any>) -> Void)
to type ((Dictionary<String, Any>) -> Void)?
. And I can't figure out why. After all, we can successfully convert non optional to optional:
var a = "hello"
var b: String? = a // correct
Why can't swift do it? Why does Swift think that Type ((Dictionary<String, Any>) -> Void)
and Type ((Dictionary<String, Any>) -> Void)?
are completely different types, and not optional variations of the same type?