Is there a difference between these two declarations? Is one better practice?
- NSString* hello = @"HelloWorld";
- NSString *hello = @"HelloWorld";
Thanks--
Is there a difference between these two declarations? Is one better practice?
Thanks--
There is absolutely no difference, although the second one I find is more popular amongst Objective-C developers.
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
(: