• 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: Can't get setDelegate to work on NSMenu attached to NSStatusItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem


  • Subject: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 3 Mar 2009 12:33:21 -0800

On Mar 3, 2009, at 11:47, Nick Zitzmann wrote:

// build NSMenu by HAND
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"abc"] autorelease];
if (menu != NULL)

You don't have to worry about this. There are a few classes that may return nil (not NULL) if initialization fails, such as NSPipe. NSMenu is not one of these classes, and most likely never will be.

This is somewhat OT, but I'm not sure if I follow you here. By design (http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_4_section_4.html#/ /apple_ref/doc/uid/TP30001163-CH22-SW13), *any* class's initializer may return nil to indicate initialization failure. I don't know of any documented API contract that says [NSMenu initWithTitle:] never fails, so checking the returned value seems prudent.


In addition, I've always assumed that 'alloc' could potentially return nil. In that case, the result of the initialization would be nil too, and so needs to be checked. (Is that wrong? Is an exception thrown if there is no memory available? If so, is that documented somewhere?)


_______________________________________________

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


  • Follow-Ups:
    • Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
      • From: Nick Zitzmann <email@hidden>
References: 
 >Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Listening key board event while application in status bar
  • Next by Date: Re: To run a block of code at every 1 second
  • Previous by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Next by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Index(es):
    • Date
    • Thread