• 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
CD: Creating a managed object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CD: Creating a managed object


  • Subject: CD: Creating a managed object
  • From: Ian Joyner <email@hidden>
  • Date: Mon, 28 May 2007 16:01:19 +1000

I have a simple app with a view with a mouse down handler. The simple core data model has an entity to track where the user has clicked. The basic architecture I have come up with is to add an outlet to the view for the NSArrayController controlling the point entities. This outlet is connected in IB to the controller. When the view is clicked mouseDown: is called:

IBOutlet NSArrayController *nsa;

.....

-(void) mouseDown: (NSEvent *)event {
   [nsa insert: self];
}

Is the view holding a reference to the controller a reasonable architecture? I'm kind of doing what a plus button would do to send add: to the controller to create a new object.

If this is OK, the next step is to change the insert to an addObject. Getting code out of the Core Data Programming Guide I'd do something like:

-(void) mouseDown: (NSEvent *)event {
NSManagedObject *point = [NSEntityDescription insertNewObjectForEntityForName: @"Point" inManagedObjectContext: context]; // Where do I get 'context'?
[point setX: event.x]; // pseudo code
[point setY: event.y];
[nsa addObject: point];
}


Problem I have with the above is that we are in a view and the managed object context belongs to the document, which the view does not know about the context, which makes me think there is something wrong with this architecture.

So is there a better way of creating a managed object when a click is received in a view? Or if this is a legitimate way of doing it, how do I get the right context to insert the managed object into?

Thanks
Ian Joyner
Sportstec

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: CD: Creating a managed object
      • From: Ian Joyner <email@hidden>
    • Re: CD: Creating a managed object
      • From: mmalc Crawford <email@hidden>
  • Prev by Date: Re: bug: unsigned short, NSArrayController, NSTableView?
  • Next by Date: Re: CD: Creating a managed object
  • Previous by thread: Making Subimages
  • Next by thread: Re: CD: Creating a managed object
  • Index(es):
    • Date
    • Thread