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?
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];
精彩评论