• 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: Cocoa Style Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa Style Question


  • Subject: Re: Cocoa Style Question
  • From: "John C. Warner" <email@hidden>
  • Date: Thu, 31 Mar 2005 15:05:40 -0500


On 31 Mar, 2005, at 1:19 PM, Adam wrote:

What is considered good cocoa style? I am sometimes tempted to be efficient and code like:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendCommandToSocket:) name:@"AGFIBSSendCommandToSocket" object:nil];

Is it better to be more clear like and break things down:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(sendCommandToSocket:) name:@"AGFIBSSendCommandToSocket" object:nil];



One thing to watch out for with the second example is something like

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(sendCommandToSocket:) name:@"AGFIBSSendCommandToSocket" object:nil];
...
[nc addObserver:self selector:@selector(appLaunched:) name:NSWorkspaceDidLaunchApplicationNotification object:nil];


You'll never receive the second notification, since NSWorkspace uses its own notification center, not the default one.

-John

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Cocoa Style Question (From: Adam <email@hidden>)

  • Prev by Date: Re: Apple's Code Level Support
  • Next by Date: More Newbie Trouble with Basic Bindings
  • Previous by thread: Re: Cocoa Style Question
  • Next by thread: A Question about and applications structure...
  • Index(es):
    • Date
    • Thread