Say I want to create an instance of NSString
, which is initialized to a certain value depending on the value of another variable. Normally, I would do
NSString *string;
if(foo == 1)
string = @"Foo is one.";
else
string = @"Foo is not one.";
However, in some sample code that I've seen, I've seen people do
NSString *string = nil;
if(foo == 1)
string = @"Foo is one.";
else
string = @"Foo is not one.";
What is the difference between these two, and which method is preferred?