On May 31, 2010, at 14:03, Richard Somers wrote:

> Apple's documentation seems to indicate that if you have an object in a nib 
> with a managed object context outlet, that you can somehow set the outlet.
> 
> The Core Data Programming Guide states "If you are setting the reference to 
> the context in a nib file, make sure the appropriate outlet or binding is set 
> correctly."
> 
> http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreData/Articles/cdTroubleshooting.html#//apple_ref/doc/uid/TP40002320-SW23
> 
> How do you set a managed object context outlet in a nib file?

You can only do this if there's also a managed object context object in the 
nib. A binding, of course, can reference a managed object context outside the 
nib, via File's Owner or another proxy object.

> Suppose that I have a custom view with a managed object context outlet and I 
> want to bind it or set it in the nib to the managed object context of the 
> File's Owner which is a subclass of NSPersistantDoument. How would you do 
> this?

You can set it yourself.

If you give the view an outlet to File's Owner, you can do it in the view's 
awakeFromNib:

        self.managedObjectContext = 
self.windowControllerOutlet.document.managedObjectContext;
// or   self.managedObjectContext = self.documentOutlet.managedObjectContext; 
(if File's Owner isn't the window controller)

If you don't want to have the extra outlet, you can do it in the view's 
didMoveToWindow:

        self.managedObjectContext = 
self.window.windowController.document.managedObjectContext;
// or   self.managedObjectContext = self.window.delegate.managedObjectContext; 
(if there isn't a window controller at all)

Of course, if you can do the above, you don't need the managedObjectContext 
outlet at all -- the view can find the managed object context at any time 
(after awakeFromNib or didMoveToWindow) using a key path reference like the 
ones above.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to