Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CD: Creating a managed object



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.