• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Better Way to Add an Entity to an ArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Better Way to Add an Entity to an ArrayController


  • Subject: Re: Better Way to Add an Entity to an ArrayController
  • From: vincent habchi <email@hidden>
  • Date: Sat, 23 Jan 2010 23:02:40 +0100

Le 23 janv. 2010 à 21:43, cocoa-dev a écrit :

> 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];
>
Why just do not use [arrayController insertObject:newTrack atOffset:0]?

> Track *newTrack = [[Track alloc] init];

If Track is somehow a subclass of NSManagedObject, then it's not the right way to create it. You should use:

NSEntityDescription * newTrackDesc = [NSEntityDescription entityForName:@"Track" inManagedObjectContext:moc];
Track *	newTrack = [[Track alloc] initWithEntity:newTrackDesc insertIntoManagedObjectContext:moc];

where "moc" is a pointer to your managed object context.

V.

_______________________________________________

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

References: 
 >Better Way to Add an Entity to an ArrayController (From: cocoa-dev <email@hidden>)

  • Prev by Date: Re: rightMouseDown not working as documented?
  • Next by Date: error accessing timer's userInfo
  • Previous by thread: Better Way to Add an Entity to an ArrayController
  • Next by thread: error accessing timer's userInfo
  • Index(es):
    • Date
    • Thread