关于“自我"的关键字 [英] About the keyword of `self`

查看:79
本文介绍了关于“自我"的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

+ (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆