Here we return id because somebody can initialize an object like this. BaseClass *base = [[DerivedClass alloc] init]; In this case, we want to make sure we have the right pointer returned from the init method. Summary:
id is a reserved keyword.
It can hold pointer to any object.
It can hold pointer to nil.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
id can hold pointer of any kind of object.
syntax:
id newPointer = somepointer;
e.g.
It will work perfectly. Here is something you should note that id keyword is not followed by an *, its because id already knows that it is a pointer.
We use this while return objects from the derived class while we overrige the init method as shown below:
-(id)init { if (self = [super init]) { someIVarObject = [SomeClass alloc] init]; } return self; }Here we return id because somebody can initialize an object like this.
BaseClass *base = [[DerivedClass alloc] init];
In this case, we want to make sure we have the right pointer returned from the init method.
Summary: