For allocation and initialization to a class, we do
Party *partyInstance = [Party alloc];
[partyInstance init];
or
Party *partyInstance = [[Party alloc] init];
Is there any special reason to use nested message? Or is it just for convenience?
For allocation and initialization to a class, we do
Party *partyInstance = [Party alloc];
[partyInstance init];
or
Party *partyInstance = [[Party alloc] init];
Is there any special reason to use nested message? Or is it just for convenience?
Yes, there is. You need to assign to your object the return value of init
, not that of alloc
(because of class clusters). And writing
Party *partyInstance = [Party alloc];
partyInstance = [partyInstance init];
would be quite awkward.