为什么init不是类方法? [英] Why is init not a class method?
本文介绍了为什么init不是类方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 init
方法不是类方法?我的意思是 init
的方法体以 -
开头。
根据我所知,以 -
开头的方法是实例方法,但显然我们要创建一个实例。
Why is the init
method not a class method? I mean init
's method body starts with an -
.
Methods starting with -
are instance methods as far as I know, but obviously we want to create an instance.
推荐答案
init
不适用于实例; alloc
的作业(和 alloc
是类方法)。
init
is not for creating an instance; that's alloc
's job (and alloc
is a class method).
init
用于设置创建的实例。它需要访问新实例的ivars,并且必须是一个实例方法。
init
is for setting up the created instance. It needs access to the new instance's ivars, and must be an instance method.
这篇关于为什么init不是类方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文