0

I want an array that can only contain a certain type of object.

How can I achieve this?

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
Mil0R3
  • 3,876
  • 4
  • 33
  • 61

1 Answers1

1

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.

melsam
  • 4,947
  • 1
  • 22
  • 23