Reputation: 10390
I have the following utility method declared, where "players" is a NSMutableArray object and a property of my application's view controller. My problem is that "players" still has 0 objects after this method is called.
-(void)addPlayerNamed:(NSString *)name withLife:(NSNumber *)life{
NSMutableDictionary *newPlayer = [NSMutableDictionary dictionaryWithCapacity:1];
[newPlayer setObject:life forKey:name];
[players addObject:newPlayer];
}
Upvotes: 0
Views: 91
Reputation: 1316
Have you set players to anything? You have to call this before using it, maybe in the initialiser.
players=[[NSMutableArray alloc] init];
If players is a property, you probably also want to use
self.players
instead of
players
(Although the latter will still work)
Upvotes: 2
Reputation: 237060
In all likelihood, players
is nil. Any message to nil returns 0 or nil.
Upvotes: 2