ios - JSon and Ambiguos use of subscript -
i'm developing ios application , latest updates go t error : ambiguous use of subscript
for code :
let json: anyobject = try nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.mutablecontainers) return (json[0]) as! nsdictionary is there solution? thank you.
since annotate json anyobject compiler not able infer type if it's dictionary (key subscription) or array(index subscription). that's ambiguity.
the solution cast object proper type
let json = try nsjsonserialization.jsonobjectwithdata(data!, options: []) as! [[string:anyobject]] return json[0] ps: use swift native collection types. foundation nsarray , nsdictionary don't contain type information , option .mutablecontainers not needed in of cases.
Comments
Post a Comment