I created a mutable array and I have two NSString variables. Now I want to add these two NSStrings to my array. How is this possible? Thanks.
-
2use addObject: from nsmutable array i hope this is enough for you...ajay– ajay2011-04-15 05:59:08 +00:00Commented Apr 15, 2011 at 5:59
Add a comment
|
3 Answers
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);