On Apr 26, 2012, at 1:00 PM, Chris Tracewell wrote:

> I usually use the sample in line 1 when declaring vars inside my methods.
> 
> NSString *theString = [NSString string];

If you are going to assign another value to 'theString' before you use it, then 
doing this is pointless.

> 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?

In C unless you explicitly initialize a local variable its value is undefined, 
and Objective-C inherits this behavior.

I believe however that under ARC these lines are equivalent (at least thats my 
reading of section 4.2 on initialization at 
<http://clang.llvm.org/docs/AutomaticReferenceCounting.html>) but given your 
comments I suspect you are not using ARC.
--
David Duncan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to