kuemme01 kuemme01 - 7 months ago 50
Swift Question

Ambiguous use of 'subscript' after converting to swift 2.3

I got this Errors after I converting to swift 2.3.

guard let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary else {
throw JSONError.ConversionFailed

let loadedWeather = json["weather"]![0]["description"] as? String,
let loadedTemperatur = json["main"]!["temp"] as? Float,
let loadedWindSpeed = json["wind"]!["speed"] as? Float
else {
print("Weather JSON-Parsing failed")

Ambiguous use of subscript
error comes by declaring "loadedWeather, loadedTemperatur and loadedWindSpeed".

Already tried to change NSDictionary to Dictionary and other things, helped on another position in code, but here....

thanks guys


I think that the issue is that the compiler cannot work out what json["weather"] is, You may need to be more specific in your code.


let loadedWeather = (json["weather"] as! [[String:AnyObject]])[0]["description"] as? String