My data model

I generated to subclasses Pack and Class. In Pack.m I can see the following
#import "Pack.h"
#import "Card.h"
@implementation Pack
@dynamic packTitle;
@dynamic card;
- (void)addCardObject:(Card *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"card" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"card"] addObject:value];
[self didChangeValueForKey:@"card" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)removeCardObject:(Card *)value {
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"card" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"card"] removeObject:value];
[self didChangeValueForKey:@"card" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)addCard:(NSSet *)value {
[self willChangeValueForKey:@"card" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitiveValueForKey:@"card"] unionSet:value];
[self didChangeValueForKey:@"card" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
- (void)removeCard:(NSSet *)value {
[self willChangeValueForKey:@"card" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
[[self primitiveValueForKey:@"card"] minusSet:value];
[self didChangeValueForKey:@"card" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}
@end
All those methods were generated by xcode as not public. I tried to make the first one to be a public method and write to the database this way in my viewController where inputCardPack is array of arrays.
Pack* pack = [NSEntityDescription insertNewObjectForEntityForName:@"Pack" inManagedObjectContext:self.context];
pack.packTitle = self.inputCardPackTitle;
for (int i = 0; i< [self.inputCardPack count]; i++ ){
NSNumber *level = [NSNumber numberWithInt:0];
Card *card = [NSEntityDescription insertNewObjectForEntityForName:@"Card" inManagedObjectContext:self.context];
card.term = [[self.inputCardPack objectAtIndex:i] objectAtIndex:0];
card.def = [[self.inputCardPack objectAtIndex:i] objectAtIndex:1];
card.level = level;
//I'm trying to add a card to pack
[pack addCardObject:card];
}
It does not work, I'm getting an error on the last line. If I remove the last line, it works. Questions: is it right approach to use those generated methods? How to get all cards belonging to defined Pack?