You must tell the compiler that the intermediate object is on the line
let obj = jsonResult["levels"]![i] as! NSDictionary
After approval jsonResult["levels"]! the compiler does not know what object it is dealing with. You should say this is an NSArray or something else:
let obj = (jsonResult["levels"] as! NSArray)[i] as! NSDictionary
Of course, you must additionally make sure that you can really do all this casting and that the objects inside json are really the expected type.
Even a little shorter using just one cast, directly using an NSDictionary array:
let obj = (jsonResult["levels"] as! [NSDictionary])[i]
The rationale remains unchanged: you tell the compiler what kind of jsonResult["levels"] . It should be an array containing NSDictionary s.
source share