I try to add object to my NSMutable array in my method, but keep getting error. It works, if I add the object in init. It doesn’t say that anything is wrong until I try to execute the code.
This is below the #import stuff where I declare two arrays:
NSMutableArray *actions1, *actions2;
This is in init:
actions1 = [NSMutableArray array];
Here I try to add 1 to the array:
- (void) storeAction:(int) action {
[actions1 addObject:@"1"];
}
The same code works in int as I said earlier.
I also would like it to store the int value declared “action”, but this didn’t seem to work either.
[addObject:@"%d", action];
[NSMutableArray array];is returning an autoreleased object, by the time you try to access it, it is most likely deallocated already. Try[[NSMutableArray alloc] init];instead. And than you should urgently check the memory management rules.