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?

bdv
  • 1,154
  • 2
  • 19
  • 42

1 Answers1

1

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

Janum Trivedi
  • 1,660
  • 2
  • 16
  • 24