Re: NSWindowControllers and NSWindow
Re: NSWindowControllers and NSWindow
- Subject: Re: NSWindowControllers and NSWindow
- From: Jens Alfke <email@hidden>
- Date: Mon, 16 Feb 2015 09:37:58 -0800
> On Feb 16, 2015, at 6:17 AM, Dave <email@hidden> wrote:
>
> My initial thought were to have a WindowController:
> LTWMainWindowController that looks after a number of Windows.
Usually you have a separate NSWindowController subclass for each distinct type of window. If the windows share some functionality, put it in a base class and subclass it. Otherwise if you try to do everything with one controller class, you end up with a lot of “switch(_windowType) {…}” stuff, which is a code smell meaning “subclass me!”
As others have pointed out, you almost never subclass NSWindow. The only reason to do that is if you want to do something special to the appearance or behavior of the window frame itself. For example, Chrome has a custom NSWindow class to handle drawing the tabs in the window frame.
One thing no one’s mentioned yet is NSDocument. If your app supports the typical behavior of opening a file into a window, you probably want to use NSDocument, which provides a framework for opening/saving documents, tracking the ‘dirty’ state, working with iCloud storage, etc.
—Jens
_______________________________________________
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