本文介绍了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中的任何其他隐式转换不同,并且是可可中大多数容器类型的基础.

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是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:11