MattSaedi
(Matt Saedi)
1
how can I fix Type 'Any' has no subscript members error
this is my code
tkrajacic
(Thomas Krajacic)
2
Well, when you cast someArray to an NSArray it doesn't know what the elements inside this array are. So the items are of type Any . You can check if the item itself is a dictionary and then if this dictionary contains a String for the key "fname".
If the structure of your JSON is always the same, you will be a lot happier using Swift's Codable instead of JSONSerialization.
Take a look here: Apple Developer Documentation
MattSaedi
(Matt Saedi)
3
thank dear but I didn't understand how can I write with Codable
can you write my code with Codable?
tkrajacic
(Thomas Krajacic)
4
You will need to know the structure of the JSON that is being returned from the server and create a struct or class that matches this structure.
I strongly suggest you look at the link I shared and download the sample code there. The playground shows you in real code how Codable works.