1, Party *partyinstance = [Party alloc]; [Partyinstance Init]; Because any object must be created and initialized before it can be used, the above two messages should be written in one line of code, with the following code:
party *partyinstance = [[Party alloc] init];
This practice of writing two messages together in a single line of code is called nested message sending (nested messages send). The program executes the code in the innermost square brackets first, so the party class receives the ALLOC message first. The Alloc method then returns a pointer to the newly created object. Finally, the uninitialized object receives the INIT message, returns the initialized object pointer, and saves the pointer in the variable.
---------------------------------------------------------------------------------------------------------
2, tags and parameters must be paired with the syntax is an important feature of objective-c. In other languages, this line of code might be written as:
Partyinstance.addattendeewithdish (Someperson, Deviledeggs);
In these languages, the individual values of the incoming function correspond to which parameters are not obvious. In Objective-c, each value will be paired with the corresponding tag, with the following code:
[Partyinstance Addattendee:someperson Withdish:deviledeggs];
Remember here that each set of square brackets corresponds to only one message that needs to be sent. Although the addattendee:withdish here: there are two tags, but still only a message, sending this message will only trigger a method.
--------------------------------------------------------------------------------------------------------
3
iOS Programming (Fourth Edition) Notes--to be continued