【发布时间】:2014-03-20 20:08:42
【问题描述】:
我在编写 Objective-C 类时使用了以下便捷的方法结构:
+ (MyClass *) myClass {
return [[[self alloc] init] autorelease];
}
- (id) init {
if (self = [super init]) {
// set-up code here...
}
return self;
}
有什么理由为什么便捷方法应该指定返回类型MyClass*而不是id?或者init 方法应该指定任一返回类型?
这似乎是 Objective-C 代码中的常见模式。直到现在才真正考虑过。
【问题讨论】:
标签: objective-c return-type convenience-methods