// : Playground - noun: a place where people can play
import UIKit
//: 自动引用计数(Automatic Reference Counting)
//自动引用计数实践 classPerson0 { let name: String init(name: String) { self.name = name print("\(name) is being initialized") } deinit { print("\(name) is being deinitialized") } }
var reference1: Person0? var reference2: Person0? var reference3: Person0?
classCountry { let name: String var capitalCity: City! init(name: String, capitalName: String) { self.name = name self.capitalCity =City(name: capitalName, country: self) } } classCity { let name: String unownedlet country: Country init(name: String, country: Country) { self.name = name self.country = country } }
var country: Country? country =Country(name: "Canada", capitalName: "Ottawa") print("\(country!.name)'s capital city is called \(country!.capitalCity.name)") country =nil