Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put different types of objects in the same NSMutableArray?

I have classes A and B.
Can I put these classes in the same NSMutableArray without problems in future?

Example:

NSMutableArray *maincoll = [[NSMutableArray alloc] init];
ClassA *ca = [[classA alloc] init];
ClassB *cb = [[classB alloc] init];
//here is case
[maincoll addObject:ca];
[maincoll addObject:cb];
...
like image 360
Fish Avatar asked Oct 26 '11 13:10

Fish


2 Answers

Yes. No limitations. The only thing you have to be careful of is when you retrieve items from the array to verify their class (if necessary) before starting to use them.

like image 151
pmeyer Avatar answered Oct 03 '22 10:10

pmeyer


Yes.

This may be the shortest answer I've ever posted.

like image 40
jrturton Avatar answered Oct 03 '22 10:10

jrturton