There's often confusion about the difference between the following three declarations in Objective-C: id foo1; -> It simply declares a pointer to some Objective-C object, If you don't want (or can't have) any type checking, then use id . if you do want compile-time type checking, you must decide between the second and third cases.. NSObject *foo2; -> declaring a generic pointer of type NSObject* id<NSObject> foo3; -> pointer to any object that behaves like an NSObjec , "foo3 is a pointer to an object of any type that behaves like an NSObject" , ( you really don't care what class the object is, you only care that it behaves like an NSObject.) The first one is the most common. It simply declares a pointer to some Objective-C object (see /usr/include/objc/objc.h ). id gives the compiler no information about the actual type of the object, so the compiler cannot do compile-time type ...
helo
ReplyDelete