• 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
Re: How to reference a NSDocument from a NSView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to reference a NSDocument from a NSView?


  • Subject: Re: How to reference a NSDocument from a NSView?
  • From: Negm-Awad Amin <email@hidden>
  • Date: Wed, 20 Aug 2008 14:12:33 +0200


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@hidden> 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 (email@hidden)

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:
This email sent to email@hidden

Amin Negm-Awad email@hidden




_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >How to reference a NSDocument from a NSView? (From: "Jeff Mesnil" <email@hidden>)
 >Re: How to reference a NSDocument from a NSView? (From: "Jeff Mesnil" <email@hidden>)
 >Re: How to reference a NSDocument from a NSView? (From: Scott Anguish <email@hidden>)

  • Prev by Date: Re: best way to determine if portion of window is visible?
  • Next by Date: Re: Best Way to Handle Properties?
  • Previous by thread: Re: How to reference a NSDocument from a NSView?
  • Next by thread: NSATSTypesetter Line computation problem
  • Index(es):
    • Date
    • Thread