3

I have mutable string array named arrayout. It is having 3 element .Now I want to add 1 String element that array.But when I try to add,it is taking null value....Cant get what to do...Please help...

My code is :

       NSString *ds1 = @"--";
        [arrayout arrayByAddingObject:ds1];
        NSLog(@"arrrrr '%@'",arrayout);
1
  • 1
    As written in the documentation; arrayByAddingObject creates a NEW array instead of appending to arrayout. Commented Dec 7, 2012 at 11:49

3 Answers 3

6

Try this out:

NSString *ds1 = @"--";
[arrayout addObject:ds1];
NSLog(@"arrrrr '%@'",arrayout);

Hope this helps you.

Sign up to request clarification or add additional context in comments.

Comments

4

You can also do it this way:

NSMutableArray *arrayout = [[NSMutableArray alloc] init];        // alloc here
[arrayout insertObject:@"SomeText Here" atIndex:[arrayout count]];  // insert here
NSLog(@"Appended Array: '%@'",arrayout);                      // Print here

this will populate arrayout with SomeText Here.

Hope it helps!

Comments

2

Why are you concatenating strings like this ? You can just do something simple like

NSString* newString = [NSString stringWithFormat:@"%@/%@/%@", string1, string2, string3];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.