Reputation: 183569
Is there a difference between these two declarations? Is one better practice?
Thanks--
Upvotes: 1
Views: 164
Reputation: 1373
dreamlax's answer is correct but I would like to make the things more clear, the compiler strips whitespaces, both examples will be converted to NSString*hello=@"HelloWorld"; so there is no difference at all, use the one you feel more comfortable with. I prefer the second one, because its more clear (I read all declarations from right to left):
NSString *hello = @"HelloWorld";
^ ^ ^
3 2 1
1 => We have string value 2 => Pointer variable pointing to the address in memory where our object value is stored 3 => Object is of type NSString
(:
Upvotes: 3
Reputation: 95335
There is absolutely no difference, although the second one I find is more popular amongst Objective-C developers.
Upvotes: 4