Automatic reference counting | What is swift ARC | Memory management in swift
| class Person | |
| { | |
| var name: String | |
| weak var job: Job? // Weak to remove the reference count or Retin count | |
| init(_name: String) { | |
| debugPrint("init method of Person called") | |
| name = _name | |
| } | |
| func printName() { | |
| debugPrint("name is \(name)") | |
| } | |
| deinit { | |
| debugPrint("deinit called for person class") | |
| } | |
| } | |
| class Job | |
| { | |
| var jobDescription: String | |
| weak var person: Person? | |
| init(_jobDescription: String) { | |
| debugPrint("init method of Job called") | |
| jobDescription = _jobDescription | |
| } | |
| deinit { | |
| debugPrint("deinit called for job class") | |
| } | |
| } | |
| if (1 == 1) | |
| { | |
| let objPerson = Person(_name: "codect15") | |
| let objJob = Job(_jobDescription: "swift programmer") | |
| objPerson.job = objJob | |
| objJob.person = objPerson | |
}
|