0

I want to add a first an last name to one index of a mutable array.

I'm loading a first and last name from the AdressBook API and I want the first and last name in an array, so I can display that later to the user.

Currently, I can log the first an last name, but when I try to add these to an array, the array stays null.

This is the code I'm using:

[_names addObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName]];
NSLog(@"%@", _names); //prints 'null'

NSLog(@"Name:%@ %@", firstName, lastName);//prints 'John Appleseed'

Why isn't my array being updated?

0

1 Answer 1

1

Have you made sure you initiated the array properly using _names = [[NSMutableArray alloc] init]? You cannot add objects into an uninitialized array.

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

1 Comment

That's it. I'm officially ashamed now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.