Raju
Raju

Reputation: 3469

NSArray with values

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

Answers (3)

Mak
Mak

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

oxigen
oxigen

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

nevan king
nevan king

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

Related Questions