Skip to content

Instantly share code, notes, and snippets.

@haikieu
Created May 24, 2019 21:13
Show Gist options
  • Save haikieu/c7ec579180b22297a363cfb5abee7751 to your computer and use it in GitHub Desktop.
Save haikieu/c7ec579180b22297a363cfb5abee7751 to your computer and use it in GitHub Desktop.
Circular reference with closure
import UIKit
class Student {
var name: String
var age: Int
init(_ name: String, age: Int) {
print("Hello student \(name)")
self.name = name
self.age = age
}
deinit {
print("Bye Student \(name)")
}
lazy var summaryInfo: () -> Void = {
print("Student \(self.name) age \(self.age)")
}
}
do {
let student = Student("Andrew", age: 19)
let summary = student.summaryInfo()
print("\(summary)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment