In Swift, how to check if an object is a collection of any type?

I am working on creating a JSON visualizer ( UIScrollViewwith extensible views for each value) and I am having a problem:

I have NSDictionaryreturned NSJSONSerialization.JSONObjectWithData. I want to check the values ​​of its objects and find out which of them are Arrays or Dictionaries.

Ideally, I hope that Arrays and dictionaries have a basic type, such as Collectionor Iterable, so that I do not have to process them separately. If they do not have this basic type, how can I check if this NSDictionary.objectForKeycollection is?

+1
source share
1 answer

You can try like this

if object is NSDictionary {

} else if object is NSArray {

}

, .

+3

Source: https://habr.com/ru/post/1664248/


All Articles