关于“自我"的关键字 [英] About the keyword of `self`
问题描述
+ (void)Foo;
- (void)Foo;
在方法- (void)Foo
中,关键字self
表示该类的实例.
但是在方法+ (void)Foo
中,关键字self
是什么意思?是Class
的意思吗?
In the method, - (void)Foo
, the keyword self
means an instance of the class.
But in the method, + (void)Foo
, What does the keyword self
mean? Does it mean the Class
?
推荐答案
self
是每个方法的两个隐式参数之一.它是一个指向对象的指针,最初是任何接收到消息以调用正在执行的方法的对象.当所讨论的方法是实例方法时,self
将是定义该方法的类或其子类之一的实例.对于类方法,self
将是类对象.
self
is one of the two implicit parameters to every method. It is a pointer to an object, and initially it is whatever object received the message to invoke the method that's executing. When the method in question is an instance method, self
will be an instance of the class in which the method is defined, or one of its subclasses. In the case of a class method, self
will be the class object.
这篇关于关于“自我"的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!