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?

4
  • 1
    Are you using an NSMutableArray? Irrespective, we need to see the code. Also, where are you expecting the string data to come from? Commented Dec 19, 2010 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. Commented Dec 19, 2010 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. Commented Dec 19, 2010 at 17:33
  • Sorry I meant array. I have declared the array earlier. Commented Dec 19, 2010 at 18:10

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

1 Comment

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!

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.