0

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

How can I achieve this?

Ben Trengrove
  • 6,934
  • 3
  • 35
  • 55
Mil0R3
  • 3,484
  • 4
  • 29
  • 56

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,807
  • 1
  • 20
  • 22