• 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: Declaring Variables - Setting to nil VS Not Setting?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declaring Variables - Setting to nil VS Not Setting?


  • Subject: Re: Declaring Variables - Setting to nil VS Not Setting?
  • From: Sean McBride <email@hidden>
  • Date: Thu, 26 Apr 2012 16:34:12 -0400

>I usually use the sample in line 1 when declaring vars inside my methods.
>
>NSString *theString = [NSString string];
>NSString *theString = nil;
>NSString *theString;
>
>I thought lines 2 and 3 were the same thing. I was wrong. What is the
>difference and when do you use the style shown in line 3?

Fritz is spot on.  In addition, note that forms 2 and 3 are only the same under the ARC memory model, and is only the case for pointers to Obj-C objects.  This is a very new change to Obj-C.

Sean



_______________________________________________

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

References: 
 >Declaring Variables - Setting to nil VS Not Setting? (From: Chris Tracewell <email@hidden>)

  • Prev by Date: Re: Declaring Variables - Setting to nil VS Not Setting?
  • Next by Date: Re: Declaring Variables - Setting to nil VS Not Setting?
  • Previous by thread: Re: Declaring Variables - Setting to nil VS Not Setting?
  • Next by thread: Save panel showing as a blank sheet
  • Index(es):
    • Date
    • Thread