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 (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:
> http://lists.apple.com/mailman/options/cocoa-dev/citizen%40zenopolis.com
> 
> This email sent to citi...@zenopolis.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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to