1, Object storage details, 2, #pragma mark Directive, 3, difference between function and object method, 4, relationship between object and method, 5. Classroom Exercises

Source: Internet
Author: User

1, the object's storage details,

1. When creating an object: Person *p1 = [person new], do three things:
1, application heap memory space;
2, initialize the instance variables;
3, return the first address of the application space;

2. Instance variables are saved in the heap area

3. Object methods are saved in the code area

4. A class can create multiple objects;

2, #pragma mark Directive,


Features: grouping code to facilitate code discovery and navigation

Use format: #pragma mark-

#waring a feature that waits to be processed, or a feature that is not completed

3, the difference between the function and the object method,

I. Object methods:
-(void) run;
(1) The implementation of the object method in @[email protected]
The declaration of an object method can only be written in the middle of @[email protected]

(2) Object methods begin with a-number

(3) Object methods can only be called by objects

(4) The function belongs to the entire file, can be written anywhere in the file, including @[email protected], but written in @[email protected] will not be recognized, the function of the declaration can be inside the main function can also be outside the main function.

(5) Object method belongs to object all


Two. Functions:
void Run () {
}
(1) All functions are parallel.
(2) function has no affiliation
(3) The use of the time can be directly called
(4) You cannot access member variables in an object

4, the relationship between the object and the method,

One, the object as the parameter of the method
-(void) Displayperson: (person *) person{
NSLog ("Name:%@", person->name);
}


Two, the return value of the object as a method
-(Person *) Changeperson: (person *) person{
Person->name = @ "Tang's Monk";
return person;
}

5. Classroom Exercises

1, Object storage details, 2, #pragma mark Directive, 3, difference between function and object method, 4, relationship between object and method, 5. Classroom Exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.