Home > DeveloperSection > Forums > Adding Strings into NSMutableArray
Glen Martin
Glen Martin

Total Post:27

Posted on    November-07-2015 3:53 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 583  View(s)
Rate this:
I have created 2 variables of NSString and 1 variable of NSMutableArray,
Now I want to add both string variables into mutable array.

can any one tell me how to do it?

Tarun Kumar

Total Post:214

Posted on    November-08-2015 10:45 PM

If you want to add NSString objects into array,
then I'll try to show you both Mutable and Immutable array example but I would recommend using an Immutable version:
Mutable version:

NSMutableArray *mutableObject = [[NSMutableArray alloc] init];
NSString *stringObj1 = @"string1"];
[mutableObject addObject:stringObj1];
[mutableObject addObject:@"string2"];
NSLog(@"%@", mutableObject);

Immutable version:

NSArray *immutableObject = [NSArray arrayWithObjects:@"string1", @"string2", nil];
NSLog(@"%@", immutableArray);

Modified On Nov-08-2015 10:59:06 PM

Don't want to miss updates? Please click the below button!

Follow MindStick