Better Way to Add an Entity to an ArrayController
Better Way to Add an Entity to an ArrayController
- Subject: Better Way to Add an Entity to an ArrayController
- From: cocoa-dev <email@hidden>
- Date: Sat, 23 Jan 2010 15:43:25 -0500
I have a core data app with a model where there is a one-to-many relationship between CD and Track (CD has an NSSet called tracks). The tracks are shown in an NSTableView and the content set is managed by an NSArrayController. To manually add a track the user presses the add button which runs the "add:" selector of the arrayController. Right now, to programmatically add a track I do:
[arrayController performSelector:@selector(add:) withObject:nil afterDelay:0.0];
That doesn't feel right to me. I want to create a new Track entity and add it to the CD attribute tracks which is an NSSet .
I **think** I have to do the following but I don't know how exactly:
1) "willChangeValueForKey" to the CD entity, tracks attribute, from the managedObjectContext to let it know I'm going to change the tracks attribute
2) create a new Track entity
3) add that new entity to the tracks NSSet attribute in the CD entity
4) "didChangeValueForKey"
That's what I've been trying to do and it's not working. I can get the tracks attribute. I retrieve it as an NSMutableSet. To create the new Track entity with the following I get a nil:
Track *newTrack = [[Track alloc] init];
Assuming I do successfully create a new Track entity do I just add it to the tracks set?
You can see I'm confused. Any help would be appreciated.
Thank you_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden