Having trouble adding objects to NSMutableArray in Objective C

Have you initialized your viewedCardsArray? If not you need to somewhere – this is usually done in the init method for your class:

- (id)init
{
    self = [super init];
    if(self) {
        viewedCardsArray = [[NSMutableArray alloc] init];
    }
    return self;
}

Then it is released in the dealloc method:

- (void)dealloc
{
    [viewedCardsArray release];
    [super dealloc];
}

Leave a Comment