The compound relationship of a class is the most common one in the relationship of a class.
A composite is a relationship with a, such as a person class that contains a member property, a book object, and someone has a.
As required in OC, all objects are referenced as pointers, so this relationship should be reflected as:
The object of the person class contains the address of a book object.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/7C/wKiom1bRV6byR3ejAAFDC5LOVCM808.png "title=" screen shot 2016-02-27 pm 4.00.02.png "alt=" Wkiom1brv6byr3ejaafdc5lovcm808.png "width=" "height=" 471 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:400px;height:471px;"/>
As shown in the figure, three objects are included:
Person object (created by the new method)
NSString object (the literal value of the string Object @ "Zhang San" assignment)
Book object (created by the new method)
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7C/7B/wKioL1bRW8ySFn6MAAB9otZiE0Y576.png "title=" screen shot 2016-02-27 pm 4.15.58.png "alt=" Wkiol1brw8ysfn6maab9otzie0y576.png "width=" "height=" 444 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:400px;height:444px;"/>
Obviously, the P pointer must be a local variable in a function or method, and its memory uses a stack control
All objects in the objective-c must be in the heap, so the memory of the three objects, the person, the NSString, the book, is the heap space
The memory space of person, nsstring, book is not contiguous or mutually inclusive
Person with a nsstring is represented as the address of the NSString object in the Person object
Person with a book behaves as the address of a book object in the Person object
If there are two classes in which properties are compounded, the header file contains a circular reference to each other
Using @class in the header file is the class that declares the compound, and the source file contains the header file of the class to solve the problem
Amperson.h@class Ambook; @interface amperson:nsobject {ambook * book;} @end
Amperson.m#import "AMBook.h" @implementation Amperson//... @end
Ambook.h@class Amperson; @interface ambook:nsobject {Amperson * person;} @end
Ambook.h#import "AMPerson.h" @implementation ambook//... @end
This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1745563
Objective-c (3) relationship between has a relation---object