可能重复: id和void之间的客观c差异*
例如,UIView动画委托回调方法有这个参数:
context:(void*)context为什么不简单地ID? 如果我不关心上下文,我总是通过零。 但是当我想要一个时,我传递了这个对象。 有什么不同? 为什么他们更喜欢void * over id?
Possible Duplicate: objective c difference between id and void *
For example, an UIView animation delegate callback method has this argument:
context:(void*)contextWhy not simply id? I always pass nil if I don't care about an context. But when I want one, I pass the object. What's the difference? Why did they prefer void* over id?
最满意答案
id是一个指向具有isa指针的结构的指针(它指向ObjectiveC运行时,这个“thing”是对象)。 void*只是指向可能的任何东西(可能是另一个id )的指针。
id is a pointer to a struct which has isa pointer (which denotes to ObjectiveC runtime that this "thing" is object). void* is simply a pointer to possibly anything (probably another id).
更多推荐
发布评论