my project running fine before , still runs fine if using simulator. when connect iphone , try , run project error: "ambiguous use of subscript" when retrieving json info on line:
let channels = jsonresult["channels"]?[0] as? [string: anyobject]
any remedy appreciated!
the compiler seems more type restrictive.
the result type of jsonresult["channels"]
anyobject
have compiler checking value being array.
if let channels = jsonresult["channels"] as? [anyobject], channel = channels[0] as? [string: anyobject] { // channel }
or still safer check whether array not empty
if let channels = jsonresult["channels"] as? [[string:anyobject]] !channels.isempty { let channel = channels[0] // compiler knows it's [string:anyobject] // channel }
Comments
Post a Comment