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.
Liked By
Write Answer
What is id in Objective C?
Join MindStick Community
You have need login or register for voting of answers or question.
Tarun Kumar
15-Jul-2015id 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: