Re: Document-based app: design question
Re: Document-based app: design question
- Subject: Re: Document-based app: design question
- From: Citizen <email@hidden>
- Date: Fri, 21 Oct 2011 09:13:59 +0100
One way of dealing with this is to make the method part of an informal protocol and check before calling it. Details are here:
http://cocoadevcentral.com/articles/000075.php
------
David Kennedy (http://www.zenopolis.com)
On 21 Oct 2011, at 08:39, Luc Van Bogaert wrote:
> Hi,
>
> I'm using the following piece of code in several places to get a pointer to the "active" windowController in my document-based application:
>
> NSDocument *currentDocument = [[NSDocumentController sharedDocumentController] currentDocument];
> if (!currentDocument)
> return;
>
> NSWindowController *windowController = [[currentDocument windowControllers] objectAtIndex:0];
> if (![windowController isMemberOfClass:[DSSketchLibraryWindowController class]])
> return;
>
> Obviously, I'm looking for a way to refactor this duplicate code. Since this code is used in several different classes, I need to put it someplace where I can easily reference it. AppDelegate comes to mind. So, I'm wondering if putting this code in a public method in the application delegate would be the correct "cocoa way" of doing things?
>
> Thanks for any advice.
>
> --
> Luc Van Bogaert.
> _______________________________________________
>
> 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
_______________________________________________
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