Search code examples
objective-cxcode3.2

How to add variable to array in Objective-C?


I have the code [usrs addObject:usrString] I am trying to make it so that the program adds whatever the string usrString is to the array every time that you press a button, and that the string is different every time. However, whenever I run this code, it doesn't do anything. It doesn't even add an object to the array. How can I make this code do what I want?


Solution

  • I am going to take a shot in the dark and say that you forgot to alloc/init your NSMutableArray. In Objective-C, sending messages to nil will fail silently.

    e.x.

    myArray = [[NSMutableArray alloc] init];