Reputation: 3469
How can I create an NSArray with values populated?
That is to say:
NSArray *name=[NSArray alloc];
// insert these values: raju, biju.ramu
Upvotes: 2
Views: 15809
Reputation: 46
NSMutableArray *name=[[NSMutableArray alloc]init];
for(int i=0;i<=10;i++)
{
NSString *nm=[NSString stringWithFormat:@"Raju %d",i];
[name addObject:nm];
}
Upvotes: 1
Reputation: 6263
If you need to modify an existing array, You must use NSMutableArray
NSMutableArray *name=[[NSMutableArray alloc]init];
[name addObject: @"raju"];
[name addObject: @"biju"];
Upvotes: 11
Reputation: 113747
Use the NSArray initWithObjects method, remembering to put nil in as the last value:
NSArray *names = [[NSArray alloc] initWithObjects:@"raju", @"biju", @"ramu", nil];
Upvotes: 21