id的含义是什么? [英] What is the meaning of id?

查看:54
本文介绍了id的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在(试图)学习 Objective-C 并且我不断遇到这样的短语:

I am (trying to) learn Objective-C and I keep coming across a phrase like:

-(id) init;

我明白id是Objective C语言的关键字,但是编译器根据指针类型转换规则专门处理id"是什么意思?

And I understand id is an Objective C language keyword, but what does it mean to say "the compiler specifically treats id in terms of the pointer type conversion rules"?

id 是否自动将其右侧的对象指定为指针?

Does id automatically designate the object to its right as a pointer?

推荐答案

id 是一个指向任何类型的指针,但与 void * 不同的是,它总是指向一个 Objective-C 对象.例如,您可以将 id 类型的任何内容添加到 NSArray,但这些对象必须响应 retainrelease.

id is a pointer to any type, but unlike void * it always points to an Objective-C object. For example, you can add anything of type id to an NSArray, but those objects must respond to retain and release.

编译器很高兴您将任何对象隐式转换为 id,也很高兴您将 id 转换为任何对象.这与 Objective-C 中的任何其他隐式转换不同,并且是 Cocoa 中大多数容器类型的基础.

The compiler is totally happy for you to implicitly cast any object to id, and for you to cast id to any object. This is unlike any other implicit casting in Objective-C, and is the basis for most container types in Cocoa.

这篇关于id的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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