Reputation: 139
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];
Upvotes: 2
Views: 100
Reputation: 3703
Alternatively, in your header file:
@property(nonatomic, strong)NSMutableArray *actions1;
Then in the implantation file:
@synthesize actions1 = _actions1;
Then you can access your array as self.actions1
.
Upvotes: 0
Reputation: 1740
Try out this code
actions1 = [[NSMutableArray alloc] init];
Hope this helps.
Upvotes: 2
Reputation: 52237
[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.
Upvotes: 5