什么是id,与void *的区别
id在Objective C中是一个类型,一个complier所认可的Objective C类型,跟void *是不一样的,比如一个 id userName, 和void *pUserName,[userName print] 是可以的,但[pUserName print] 在编译时就会报错,因为ObjeciveC的编译器看到id,会假定它可以接受任何message,虽然在runtime时可能并不是这样的,但pUserName并不是Objective C类型,编译器就会报错,但是void *有可能时可以接收print message的。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
/** * Type for Objective-C objects. */ typedef
struct objc_object { /** * Pointer to this object‘s class. Accessing this directly is STRONGLY * discouraged. You are recommended to use object_getClass() instead. */ #ifndef __OBJC_RUNTIME_INTERNAL__ __attribute__(( deprecated )) #endif Class isa; } * id ; |
id 与 NSObject *的区别
id与instanceType
什么时候应该用id
init 方法的实现
convience constructor
http://tewha.net/2013/02/why-you-should-use-instancetype-instead-of-id/
http://stackoverflow.com/questions/7903954/why-use-id-when-we-can-just-use-nsobject
理解Objective C 中id,布布扣,bubuko.com
原文:http://www.cnblogs.com/whyandinside/p/3663169.html