Created
May 24, 2019 21:13
-
-
Save haikieu/c7ec579180b22297a363cfb5abee7751 to your computer and use it in GitHub Desktop.
Circular reference with closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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