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.
精彩评论