~ Weak 和Objective-C的很像 (auto niled)
~ Weak references are optional values
~ Binding the optional produce a strong reference:
if let tenant = apt.tenant {
tenant.buzzin()<span style="white-space:pre"> </span>//tenant is of weak attribute
}
alternatively:
apt.tenant?.buzzIn()
Examples:
class Person {
var card: CreditCard?
}
class CreditCard {
weak var holder: Person? //could be set to nil anytime
init(holder: Person) {
self.holder = holder
}
}
* Use strong reference from owners to the object they own
* Use weak reference among objects with independent lifetimes
* Use unowned references from owned objects with the same lifetime (反向指向strong)