Adding Strings into NSMutableArray

Posted by  Glen Martin
 1181  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?
  1. Re: Adding Strings into NSMutableArray

    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 Apr-10-2018 05:31:18 AM