开发者

Objective-C and autorelease on return

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜