> On Dec 5, 2015, at 05:24 , Jerry Krinock <je...@ieee.org> wrote:
> 
> 
>> On 2015 Dec 04, at 16:32, Rick Mann <rm...@latencyzero.com> 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
rm...@latencyzero.com



_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to