为什么在Objective-C中没有将"id"类型的对象初始化为带有"*"的指针? [英] Why aren't objects of type 'id' initialized as pointers with a '*' in Objective-C?

查看:75
本文介绍了为什么在Objective-C中没有将"id"类型的对象初始化为带有"*"的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用的是Objective-C,这就是我声明一个int初始化的方法:

If I'm using Objective-C, here's how I declare an initialize an int:

int a = 1;

与对象:

myObj *a = [[myObj alloc] init];

因此,这是指向由"*"表示的对象的指针.我的问题是,为什么不以这种方式声明类型为id的对象?也就是说,为什么会这样:

So this is a pointer to an object as denoted by the '*'. My question is, why aren't objects of type id declared this way? I.e., why is it this:

id genericObj;

而不是:

id *genericObj;

?

推荐答案

因为id表示标识符.标识符与指针一样,可以标识对象.标识符不是对象本身.

Because id means identifier. Identifier, like pointer, identifies the object. Identifier isn't the object itself.

如果需要,可以始终将其视为typedef <some-mysterious-root-type>* id.

You can always treat it as typedef <some-mysterious-root-type>* id if you want.

这篇关于为什么在Objective-C中没有将"id"类型的对象初始化为带有"*"的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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