从 Objective C 中的类方法中引用类本身 [英] Refering to the class itself from within a class mehod in Objective C

查看:30
本文介绍了从 Objective C 中的类方法中引用类本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我没有跳过 ObjC 手册中的这一部分,但是是否可以从类方法中的一个中引用一个类?就像在 PHP 中一样,你会使用this"来指代当前实例,而self"指的是实例的类,this"的 ObjC 等价物将是self",那么 PHP 的self"的 ObjC 等价物是什么?,如果有?

I hope i did not skip this part in the ObjC manual but is it possible to refer to a class from within one of its class methods? Like in PHP you would use "this" to refer to the current instance, while "self" refers to the instance's class the ObjC equivalent of "this" would be "self", so what would be the ObjC equivalent of PHP's "self", if there is one?

推荐答案

class 方法中,self 指的是当前类(类的 Class 对象).在 instance 方法中,self 指的是该类的当前实例.

Inside a class method, self refers to the current class (the class's Class object). Inside an instance method, self refers to the current instance of that class.

这篇关于从 Objective C 中的类方法中引用类本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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