开发者

Difference of (Object*) and (id) in Objective-C

Help me please to find out what's the difference between these two code snippets: (In the snippets Foo is a class derived from Object declared in objc/Object.h)

// Snippet 1
Object* o = [Foo new];
[o free];

// Snippet 2
id o = [Foo new];
[o free];

Thanks!

EDIT

Thanks for the helpful answers! Let me share a link that I found, maybe it'll help those, who meets the same question like me, and want to understand it bet开发者_如何转开发ter: id_vs_NSObject.


id can be anything and can respond to any message in the system without warning, as it could be of any type. Object * (do you mean NSObject *?) is strongly typed--the compiler assumes it only responds to methods that Object is known to respond to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜