On Tue, Aug 19, 2008 at 1:37 PM, Jeff Mesnil <[EMAIL PROTECTED]> wrote: > The application is behaving as expected, the model (the ovals) are > kept in MyDocument and the DrawView just draws them. > But I was wondering if that was the "right" Cocoa way to do so, to use > an IBOutlet to connect a NSView to a NSDocument. > Is there another way to have a reference to the document from one view > of the application?
Answering my own question, my use case is similar to the Sketch example bundled with XCode. In Sketch, they use KVC to observe an NSArrayController. I did the same by calling bind:toObject:withKeyPath:options: in MyDocument windowControllerDidLoadNib: method and it works. To sum up, I've seen 3 different ways to write this code: - use an IBOutlet to reference the NSDocument from a NSView - use [[[self window] windowController] document] from a NSView (thanks Chaitanya!) - forget about the NSDocument and use KVC to directly observe the ovals Using the KVC seems the most natural way to do that in Cocoa. jeff -- Jeff Mesnil [EMAIL PROTECTED] http://jmesnil.net/weblog/ _______________________________________________ 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 [EMAIL PROTECTED]