0

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?

  • just convenience. It is used so often that there is no "understanding" benefit to splitting it into two lines – Ben Nov 26 '14 at 18:18
  • 5
    @Ben: No. The first version is *wrong* because `init` might return a object which is different to the one being passed. – Martin R Nov 26 '14 at 18:21

1 Answers1

3

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.