• 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: "Jeff Mesnil" <email@hidden>
  • Date: Tue, 19 Aug 2008 18:52:02 +0200

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.

jeff

--
Jeff Mesnil
email@hidden
http://jmesnil.net/weblog/
_______________________________________________

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

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

  • Prev by Date: Re: Including frameworks in your app bundle
  • Next by Date: NSATSTypesetter Line computation problem
  • Previous by thread: How to reference a NSDocument from a NSView?
  • Next by thread: Re: How to reference a NSDocument from a NSView?
  • Index(es):
    • Date
    • Thread