Initially I had this code in Swift 2.1
func onSuccess(jsonData: AnyObject?){
print(jsonData["message"])
}
After I upgraded to Swift 2.2 , I got an error such as
Ambiguous reference to 'subscript'
for the line print(jsonData["message"])
I changed my code to this
func onSuccess(jsonData: AnyObject?) {
let json = (jsonData as? [String:AnyObject?]) ?? ["":""]
print(json)
}
However this statement is always failing because AnyObject? to [String:AnyObject?] type casting is not happening and getting the nil coalescing value. I want to type cast from AnyObject? to [String:AnyObject]. Is it possible?
[String:AnyObject?]does not exist at all since by definition all keys and values of a dictionary are required to be non-optional types. - vadian