Am Di,19.08.2008 um 20:46 schrieb Scott Anguish:


On 19-Aug-08, at 12:52 PM, Jeff Mesnil wrote:

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.


I think all three are actually very valid.
Yes, but the first and second approach is IMHO the worst, because the view expects a typing (some accessores) to get the data.

There is a 4th possibility: Implementing a data source.
Cheers,
Amin



although everywhere you've said KVC above needs to e replaced with KVO. :-)



_______________________________________________

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/negm-awad%40cocoading.de

This email sent to [EMAIL PROTECTED]

Amin Negm-Awad
[EMAIL PROTECTED]




_______________________________________________

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]

Reply via email to