(UIApplication *) Why is there a space before the asterisk?
-(void)applicationDidFinishLaunching:(UIApplication *) app {
after UIApplication why is there a space b开发者_如何学运维efore the asterisk?
This is a characteristic from C code, I'm fairly new to Objective-C so forgive me if this isn't proper objective C syntax. It will answer the question. The answers about it being style are mostly correct with regard to a parameter such as given in the question. Where it is an issue is when declaring multiple variables on a single line in C or C++ (this is the part where I'm not sure if Obj-C supports this).
int* i;
and
int *i;
are equivalent; however when dealing with multiple declarations
int* i, j;
is not the same as
int *i, *j;
the * is applied to the i variable and not the int, thus you require an * on each variable you wish to make a pointer.
So the purpose of having the space after the class name is a stylistic nod to that.
It is, as has been remarked, just style; but it is generally considered good style to put the space before the asterisk, rather than after (i.e. NSString *aString;
rather than NSString* aString;
, as the asterisk binds to the name, rather than the type; ref. Steve's answer).
The same style is then generally extended to when the type stands alone, such as in - (NSString *) someMethod;
or - (void) someMethodWithAnArgument:(NSString *)argumentName;
, as a matter of staying consistent.
It's just a style preference, the space doesn't mean anything in this case.
Actually, int *i;
int* i;
and (int *) i;
all mean different things. The first two are pointers. But the last is actually saying that "i" returns a pointer to an int. So in:
-(void)applicationDidFinishLaunching:(UIApplication *) app {
That is actually saying that "app" returns a pointer
精彩评论