• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSWindowController that closes itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSWindowController that closes itself
      • From: email@hidden
    • Re: NSWindowController that closes itself
      • From: Ondra Cada <email@hidden>
    • Re: NSWindowController that closes itself
      • From: "John C. Randolph" <email@hidden>
References: 
 >Re: NSWindowController that closes itself (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: AltiVec on OSX in Cocoa
  • Next by Date: Re: NSWindowController that closes itself
  • Previous by thread: Re: NSWindowController that closes itself
  • Next by thread: Re: NSWindowController that closes itself
  • Index(es):
    • Date
    • Thread