Auto reference count
First to accompany her sister to see the film, Dot code to occupy a hole.
Weak references
It can be preceded by weak
an indication that this is a weak reference. A weak reference does not hold the referenced instance, and it does not prevent the ARC from destroying the referenced instance.
You can see how to avoid circular references by using weak references in the following example:
classperson { LetNameString varApartment:apartment? Init (Name:String{self.name = name} deinit {println ("\ (name) is being deinitialized") }}classApartment { LetNumber:int weakvarTenant:person? Init (number:int) {self.number = number} deinit {println ("Apartment #\ (number) is being deinitialized") }}varWhy:person?varnumber604:apartment?why = person (name:"Why") number604 = Apartment (number:604) why!. Apartment = number604number604!. Tenant = WHYPRINTLN ("Nil 1") Why = Nilprintln ("Nil 2") number604 = Nil
No master reference
It can be preceded by unowned
an indication that this is a no-master reference. Similar to weak references, a no-master reference does not hold the referenced instance firmly. Unlike a weak reference, a non-primary reference is always valued. Therefore, no primary reference is always defined as a non-optional type.
The following example:
classCustomer { LetNameString varCard:creditcard? Init (Name:String{self.name = name} deinit {println ("\ (name) is being deinitialized") }}classCreditCard { LetNumber:int unowned LetCustomer:customer Init (Number:int, customer:customer) {self.number = number Self.customer = Customer } deinit {println ("Card #\ (number) is being deinitialized") }}varJohn:customer?john = Customer (name:"Why") john!. Card = CreditCard (number:1234_5678_9012_3456, customer:john!) John = Nil
References
- Automatic Reference Counting
[Swift] DAY14: Auto Reference count