Reputation: 3453
I created a mutable array and I have two NSString
variables. Now I want to add these two NSString
s to my array. How is this possible? Thanks.
Upvotes: 1
Views: 20409
Reputation: 10344
You can add at NSMutableArray
allocation.
Like :
NSMutableArray *test = [NSMutableArray arrayWithObjects:@"test1",@"test2",nil];
Upvotes: 0
Reputation: 2535
Jhaliya's answer is correct. +1 vote.
I added a immutable version so you can see the difference. If you dont want to remove or add more objects (NSStrings) to your container, I would recommend using an Immutable version.
Mutable version:
NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
NSString *string_one = @"One"];
[mutableArray addObject:string_one];
//Or
[mutableArray addObject:@"Two"];
NSLog(@"%@", mutableArray);
Immutable version
NSArray *immutableArray = [NSArray arrayWithObjects:@"One", @"Two", nil];
NSLog(@"%@", immutableArray);
Upvotes: 0
Reputation: 31730
Use the addObject
function of you NSMutableArray
.
eg.
[myNSMutableArray addObject:myString1];
[myNSMutableArray addObject:myString2];
Upvotes: 20