isa指针在objective-c中 [英] isa pointer in objective-c

查看:93
本文介绍了isa指针在objective-c中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从此引用:


创建新对象时,会为其分配内存,并为其
实例变量被初始化。对象变量中的第一个
是指向其类结构的指针。这个名为isa的指针给
对象访问它的类,并通过类给它继承的所有
类。

When a new object is created, memory for it is allocated, and its instance variables are initialized. First among the object’s variables is a pointer to its class structure. This pointer, called isa, gives the object access to its class and, through the class, to all the classes it inherits from.

根据我的理解阅读这个,例如,它允许以实用的方式使用内省(iOS开发),程序员可以从了解/理解这个特殊指针中获益吗?

From what I could understand reading this and this, it allows, for one, to use introspection but in a pragmatic way (iOS development), what can a programmer benefit from knowing/understanding this special pointer?

推荐答案

真正的好处是更好地理解Objective-C运行时,与C ++等静态语言相比,它实际上相当复杂。实际上, isa 指针实际上并没有真正使用,除非你是在攻击运行时做一些特别的事情。 本指南提供了更多信息它是如何被运行时使用的。

The real benefit is a better understanding of the Objective-C runtime, which is actually quite complex compared to static languages like C++. The isa pointer, in practical terms, isn't really used all that much unless you're hacking the runtime to do something special. This guide has more info on how it is used by the runtime.

你不应该直接在生产代码中使用 isa 。这就像 retainCount - 重要的是你理解它,但你不应该叫它。

You shouldn't really use the isa directly in production code. It's like retainCount - it's important you understand it but you shouldn't ever call it.

这篇关于isa指针在objective-c中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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