• 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: NSDocument and NSViewControllers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument and NSViewControllers


  • Subject: Re: NSDocument and NSViewControllers
  • From: Rick Mann <email@hidden>
  • Date: Sat, 05 Dec 2015 12:20:15 -0800

> On Dec 5, 2015, at 05:24 , Jerry Krinock <email@hidden> wrote:
>
>
>> On 2015 Dec 04, at 16:32, Rick Mann <email@hidden> wrote:
>>
>> I have an NSViewController subclass and SCNView subclass. I can get at the document from the NSViewController subclass via a rather cumbersome "let doc = self.view.window?.windowController?.document as? ModelDocument”
>
> I just happened to have done that yesterday afternoon.  It seemed like the most logical approach to me.  “Going to the source”, even via a circuitous key path, is usually more robust than adding properties for convenience.
>
> Just make sure you can guarantee that the window and view have been loaded previously in your situation, or you’ll get nil.  I’ve also used that as a key path in Cocoa Bindings.  In that case, it’s usually OK to return nil initially.

Depending on how this shapes up, I think I'm going to try to go the opposite route. That is, there will be a top-level view controller subclass that knows how to deal with one aspect of the document data. I will try to package up that aspect in a model object(s), and hand that to the view controller when its window gets created. The ideas is that the NSDocument is a client of the view controller, not the other way around. I'll probably make the document a delegate of the view controller so it can be informed of changes to the model.

This approach makes it easier to re-use the view controller in another app.

I think.


--
Rick Mann
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


  • Follow-Ups:
    • Re: NSDocument and NSViewControllers
      • From: Quincey Morris <email@hidden>
References: 
 >NSDocument and NSViewControllers (From: Rick Mann <email@hidden>)
 >Re: NSDocument and NSViewControllers (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: ARC and IBOutlet - strong vs weak......
  • Next by Date: Re: NSDocument and NSViewControllers
  • Previous by thread: Re: NSDocument and NSViewControllers
  • Next by thread: Re: NSDocument and NSViewControllers
  • Index(es):
    • Date
    • Thread