使用"Self" Objective-C中的关键字 [英] Use of "Self" keyword in Objective-C

查看:63
本文介绍了使用"Self" Objective-C中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Objective-C-何时使用"self"

Possible Duplicate:
Objective-C - When to use ‘self’

我不太了解Objective-C中"self"关键字的重要性和用法.这是我的第一种OOP语言,所以我陷入了一些概念上. 我什么时候应该使用自我"?为什么有用?

I can't understand very well the importance and the usage of the "self" keyword in objective-c. It's my first OOP language so i got stuck on some concepts. When i should use "self"? Why is it useful?

感谢您的回答!

我不明白为什么这是 Objective-C的重复帖子-当没有我想要的自我"的解释时,何时使用自我" .

推荐答案

self是Objective-C中的一个特殊变量,在实例方法内部,此变量引用调用该方法的消息的接收者(对象),而在类方法中,self将指示正在调用哪个类.

self is a special variable in Objective-C, inside an instance method this variable refers to the receiver(object) of the message that invoked the method, while in a class method self will indicate which class is calling.

self是指正在执行当前方法的实际对象,它是运行时环境自动传递给您的实例方法的不可见参数.

self refers to the actual object that is executing the current method, it is an invisible argument passed automatically by the runtime environment to your instance methods.

这篇关于使用"Self" Objective-C中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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