Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSArray: add multiple objects with same value

How can I add multiple objects to my NSArray? Each object will have the same value.

Ex.

I want the value "SO" added to my array 10 times

like image 771
Matt S. Avatar asked May 21 '10 00:05

Matt S.


1 Answers

You can initialize the array with a set of objects:

NSString * blah = @"SO";
NSArray * items = [NSArray arrayWithObjects: blah, blah, nil];

or you can use a mutable array and add the objects later:

NSMutableArray * mutableItems = [[NSMutableArray new] autorelease];
for (int i = 0; i < 10; i++)
    [mutableItems addObject:blah];
like image 200
RedBlueThing Avatar answered Sep 18 '22 15:09

RedBlueThing