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
.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…