为什么initWithCoder不返回实例类型? [英] Why does initWithCoder not return instancetype?
本文介绍了为什么initWithCoder不返回实例类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看来,Objective-C中的大多数 init
方法现在倾向于返回 instancetype
而不是 id
。参见 [UIView initWithFrame:]
, [UIViewController initWithNibName:bundle:]
, [NSArray init]
和兄弟姐妹等。但是 initWithCoder
使用 id
。为什么是这样?只是还没有更新吗?还是有一个原因必须是 id
?
It seems that most init
methods in Objective-C now tend to return instancetype
instead of id
. See [UIView initWithFrame:]
, [UIViewController initWithNibName:bundle:]
, [NSArray init]
and siblings, etc. But initWithCoder
uses id
. Why is this? Has it just not been updated yet? Or is there a reason it has to be id
?
推荐答案
它尚未更新。您仍然可以使用实例类型对其进行编码。
It is not updated yet. You can still code it with instance type.
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
//...
}
return self;
}
这篇关于为什么initWithCoder不返回实例类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文