I want an array that can only contain a certain type of object.
How can I achieve this?
I want an array that can only contain a certain type of object.
How can I achieve this?
You cannot do this. An NSMutableArray
has the addObject
method, whose parameter is an id and can be any NSObject-based object.
If you want to protect your array from accidently getting populated with bad data from other classes, make it a private ivar and access it using a public @property or method. The public method will check the class of the object that a caller is trying to add to the array before actually calling addObject
.