isa实例变量是什么?

时间:2023-01-14 09:16:56

In the NSObject Class Reference they talk about an "isa instance variable" which

在NSObject类引用中,他们讨论了一个“isa实例变量”。

is initialized to a data structure that describes the class

是否初始化为描述类的数据结构

can someone explain what I should know about this isa instance variable? What is that good for? What does isa mean? Sounds like a norm, like DIN, ISO, etc.; Any idea what that is?

有人能解释一下关于这个isa实例变量我应该知道什么吗?那有什么用?isa是什么意思?听起来像一个标准,比如DIN, ISO等等;知道那是什么吗?

2 个解决方案

#1


7  

It is used to determine a class's inheritance path. More formally:

它用于确定类的继承路径。更正式地:

When a new object is created, it is allocated memory space and its data in the form of its instance variables are initialised. Every object has at least one instance variable (inherited from NSObject) called isa, which is initialized to refer to the object's class. Through this reference, access is also afforded to classes in the object's inheritance path. - Objective-C GNUstep Base Programming Manual: Objective-C

当创建一个新对象时,它被分配内存空间,它的数据以实例变量的形式被初始化。每个对象都至少有一个实例变量(继承自NSObject),称为isa,它被初始化以引用对象的类。通过这个引用,还可以访问对象继承路径中的类。- Objective-C GNUstep Base编程手册:Objective-C

The name isa comes from the OOP concept of IS-A which is simply a relationship between two objects like this:

isa这个名字来源于OOP概念的is - a,它只是两个对象之间的关系,比如:

A dog IS-A mammal.
A car IS-A vehicle.

狗是哺乳动物。汽车是一种交通工具。

So the isa instance variable can be helpful in that it can tell you what IS-A relationships your class has in its inheritance hierarchy.

isa实例变量可以很有用,它可以告诉你类在继承层次结构中的关系。

#2


6  

It's basically the pointer to the object's class and is what the Objective-C runtime is based around. The runtime uses it to get an objects method dispatch table and anything else that's stored on the class structure. It's pretty much the only thing that every Objective-C object has to have.

它基本上是指向对象类的指针,是Objective-C运行时的基础。运行时使用它获取对象方法分派表和存储在类结构中的任何其他内容。它几乎是每个Objective-C对象必须拥有的唯一东西。

For the most part, you can completely ignore it.

在大多数情况下,你可以完全忽略它。

#1


7  

It is used to determine a class's inheritance path. More formally:

它用于确定类的继承路径。更正式地:

When a new object is created, it is allocated memory space and its data in the form of its instance variables are initialised. Every object has at least one instance variable (inherited from NSObject) called isa, which is initialized to refer to the object's class. Through this reference, access is also afforded to classes in the object's inheritance path. - Objective-C GNUstep Base Programming Manual: Objective-C

当创建一个新对象时,它被分配内存空间,它的数据以实例变量的形式被初始化。每个对象都至少有一个实例变量(继承自NSObject),称为isa,它被初始化以引用对象的类。通过这个引用,还可以访问对象继承路径中的类。- Objective-C GNUstep Base编程手册:Objective-C

The name isa comes from the OOP concept of IS-A which is simply a relationship between two objects like this:

isa这个名字来源于OOP概念的is - a,它只是两个对象之间的关系,比如:

A dog IS-A mammal.
A car IS-A vehicle.

狗是哺乳动物。汽车是一种交通工具。

So the isa instance variable can be helpful in that it can tell you what IS-A relationships your class has in its inheritance hierarchy.

isa实例变量可以很有用,它可以告诉你类在继承层次结构中的关系。

#2


6  

It's basically the pointer to the object's class and is what the Objective-C runtime is based around. The runtime uses it to get an objects method dispatch table and anything else that's stored on the class structure. It's pretty much the only thing that every Objective-C object has to have.

它基本上是指向对象类的指针,是Objective-C运行时的基础。运行时使用它获取对象方法分派表和存储在类结构中的任何其他内容。它几乎是每个Objective-C对象必须拥有的唯一东西。

For the most part, you can completely ignore it.

在大多数情况下,你可以完全忽略它。