My goal is to add a string to array, and I do that in a method which I call.
In this method, I get a null value in the array, and don't know why. I have this at the start of my class:
NSMutableArray *listOfEvents;
and a method which I call on each event:
-(void)EventList
{
[listOfEvents addObject:@"ran"];
NSLog(@"%@", listOfEvents);
}
I get (null)
in the log.
If I put the array definition NSMutableArray *listOfEvents;
in the function body, I get the string value @"ran"
, each time, so the array always has only one value, instead of having many strings named @"ran"
.
What's wrong with this? It seems that I can't understand something about arrays, even though I have read the documents a number of times.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…