PeterK
PeterK

Reputation: 4301

How do i check what type of data in an array is?

I am pulling data from a Dictionary to an array. Is there any convenient way to check what data type that data is?

Upvotes: 2

Views: 718

Answers (1)

Ben Zotto
Ben Zotto

Reputation: 71008

You can use the -isMemberOfClass: method and/or the -isKindOfClass: method to inspect the types of the objects you're looking at. These give you explicit indications of exact class or class hierarchy. -isMemberOfClass: indicates whether the object is of a given class, whilst -isKindOfClass: indicates whether the object is of a given class, or any class which inherits from that class.

Depending on what you're actually examining, and why, you should consider (credit to commenter David) looking more generally at whether the object conforms to a given protocol (-conformsToProtocol:) or even just responds to a given selector (-respondsToSelector:). You sort of want to ask type questions as generically as you can and still preserve the usefulness of the result.

That said, this is somewhat of an unusual case-- do you really have a dictionary that has values of arbitrary types that can't be known a priori from the keys? Tell us more about your data if you want more broad design help.

Upvotes: 6

Related Questions