为什么 initWithCoder 不是 return 实例类型?
Why does initWithCoder not return instancetype?
似乎 Objective-C 中的大多数 init
方法现在倾向于 return instancetype
而不是 id
。请参阅 [UIView initWithFrame:]
, [UIViewController initWithNibName:bundle:]
, [NSArray init]
and siblings, etc. But initWithCoder
使用 id
。为什么是这样?刚刚还没有更新吗?或者有什么理由必须是 id
?
暂未更新。您仍然可以使用实例类型对其进行编码。
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
//...
}
return self;
}
似乎 Objective-C 中的大多数 init
方法现在倾向于 return instancetype
而不是 id
。请参阅 [UIView initWithFrame:]
, [UIViewController initWithNibName:bundle:]
, [NSArray init]
and siblings, etc. But initWithCoder
使用 id
。为什么是这样?刚刚还没有更新吗?或者有什么理由必须是 id
?
暂未更新。您仍然可以使用实例类型对其进行编码。
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
//...
}
return self;
}