Are the two me开发者_开发问答thods
- (id) myFirstMethod
{
NSObject* anObject = [[NSObject alloc] init];
[anObject autorelease];
return anObject;
}
- (id) mySecondMethod
{
NSObject* anObject = [[NSObject alloc] init];
return [anObject autorelease];
}
identical?
Yes the both methods are identical. Whenever you write a nested function or same code in multiple lines, it is all the same after compilation.
You could do everything in the return:
- (id) myThirdMethod {
return [[[NSObject alloc]init]autorelease];
}
Yes they are identical, but all they do is to cause a compiler error.
[anObject]
is not allowed. And NSObject anObject
is also invalid syntax.
精彩评论