Re: NSWindowController that closes itself
Re: NSWindowController that closes itself
- Subject: Re: NSWindowController that closes itself
- From: "Erik M. Buck" <email@hidden>
- Date: Tue, 13 Nov 2001 22:00:24 -0600
>
NSWindow *window = [self window];
>
id delegate = [window delegate];
The above two lines merely save two unnecessary messages. This is probably
a premature optimization since this code in unlikely to be in a critical
performance path.
>
>
if(delgate && [delegate respondsToSelector:@selector(windowWillClose:)])
Testing delegate could/should have been (nil != delegate), but it is
immaterial because sending -respondsToSelector: to nil is harmless and
returns nil which also happens to be NO.
Testing (nil != delegate) is much more important that avoiding
sending -respondsToSelector: to nil since Apple could introduce a "nil
object" that has an address other than 0 yet any message to nil will still
return nil. Furthermore, the implicit conversion of the return value from
nil to NO is exactly the same thing you are doing when you test delegate
without a Boolean binary comparison operator.
Nevertheless, we are all friends and this is just a style difference or
aesthetic difference. The optimization is unimportant here. I like your
code too.
>
{
>
if([delegate windowWillClose:window])
>
[window performClose:self];
>
}
>
else
>
[window performClose:self];
>
>
Ah, that's better. ;-)
>
>
-jcr
>
>
"Bill Gates is just a white Persian cat and a Monocle away from being
>
the villain in a James Bond flick" - Dennis Miller