• 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: nil pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nil pointers


  • Subject: Re: nil pointers
  • From: Agent M <email@hidden>
  • Date: Mon, 10 Jul 2006 23:26:10 -0400

Because if you don't assign to it, then messages sent to that object are ignored instead of crashing the process.

Example:
NSString *info=nil;

if(doInfo)
	info=[InfoMaker ...];
...
[info populate]; //I don't have to check for nil

Another use of nil is messaging to hash values:
[(NSWindowController*)[_windowControllers objectForKey:@"window X"] showWindow:self]; //don't bother checking for nil


jcr is also right that it is a matter of style too. Personally, I prefer the old-school declarations:
NSString *gonk,*splonk,*conn=nil;


gonk=[...];
splonk=[...];
conn=[...];

because:

NSString *gonk=[NSString stringWithFormat:...],*splonk=[sender window],*conn=[...];

gets cluttered fast.

On Jul 10, 2006, at 10:59 PM, Adam Johnson wrote:

why do Cocoa developers declare pointers as nil, then define them?
ex.
 NSMethodSignature * sig = nil;
 sig = [[self class] instanceMethodSignatureForSelector:mySelector];
wouldn't it be easier just to do this?

 NSMethodSignature * sig = [[self class]
 instanceMethodSignatureForSelector:mySelector];

Thanks in advance for clarifying this

¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ AgentM email@hidden ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬ ¬

_______________________________________________
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: 
 >nil pointers (From: "Adam Johnson" <email@hidden>)

  • Prev by Date: Re: nil pointers
  • Next by Date: Re: Motion Sensor
  • Previous by thread: Re: nil pointers
  • Next by thread: Re: nil pointers
  • Index(es):
    • Date
    • Thread