After writing the class declaration and implementation, how can an application call it?
In objective-C, the simple format of calling a method is as follows:
[Instance method]; for example, [person setage: 32]; where person is an instance of the person class.
Or:
[Class Name and method name]; for example: nsstring STR = [nsdate date]; this is to directly call the method date in the nsdate class to obtain the current date and time.
In objective-C, calling a class or an instance method is also called sending a message to this class or instance ). Class instance is called "receiver ". Therefore, the format of common method calls can also be understood:
[Receiver message];
In terms of terms, the entire expression is also called a message expression. This is the official name.
Of course, a method may have parameters or multiple parameters. Therefore, the complete method call format is as follows:
[Receiving Method Name sub-1: parameter 1 sub-2: parameter 2 sub-3: parameter...]
For example:
[Person setage: 32];
[Person setname: @ "Sam" andsecondname: @ "job"];
Note: When calling Multiple Parameter methods, you can omit the method name starting from the second.
For example:
[Person setname: @ "Sam": @ "job"];
You can call another method in a method, for example:
[Nsstring stringwithformat: [test format];
Note: To call a method, you must add the brackets "[......]".