0

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?

thkala
  • 84,049
  • 23
  • 157
  • 201
user457303
  • 157
  • 1
  • 3
  • 9
  • 1
    Are you using an NSMutableArray? Irrespective, we need to see the code. Also, where are you expecting the string data to come from? – John Parker Dec 19 '10 at 16:32
  • I think this may be a rephrase of middaparka's question: have you actually created an array, or merely declared a pointer to one in your class? All objects have to be explicitly created in Objective-C. – Tommy Dec 19 '10 at 16:34
  • I have declared the variable previously, it is a mutable array, and the string data comes from the input from a textbox, which I convert into a string. – user457303 Dec 19 '10 at 17:33
  • Sorry I meant array. I have declared the array earlier. – user457303 Dec 19 '10 at 18:10

1 Answers1

1

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];
Sam
  • 2,707
  • 20
  • 25
  • This solved part of my problem thanks! However, I still would like to know how to make it add whatever string the user inputs. Thanks again! – user457303 Dec 19 '10 at 21:11