I'll preface my question by saying that I'm a beginner objective-c developer. What is the difference between:
NSString * foo;
NSString* foo;
NSString *foo;
Is there a difference?
I'll preface my question by saying that I'm a beginner objective-c developer. What is the difference between:
NSString * foo;
NSString* foo;
NSString *foo;
Is there a difference?
All three simply declare a variable named foo of type NSString *. It is really just a matter of style preference.
Some people prefer to put the asterisk next to the type to emphasize that this is a pointer type.
Some people prefer to put the asterisk next to the variable to emphasize the requirements of the language. Every pointer variable in a multiple declaration needs to have the asterisk, as in:
NSString *foo, *bar;
My personal preference is actually the first of your examples with a space before and after the asterisk, reserving the use of an asterisk directly before the variable for use in dereferencing the pointer. I also avoid declaring more than one variable in a single declaration.
There is no difference, they mean all three the same thing. Only it is considered to be better to declare it like:
NSString *foo;
Because when you add a second variable your intention is more clear:
NSString *foo,*bar;