I have a class named PERSON to test memory leak. Here are the contents of class:
let name: String
private var actionClosure: (() -> ())!
init (name: String) {
self.name = name
self.actionClosure = {
println("I am (self.name)")
}
}
func performAction () {
actionClosure()
}
deinit {
println("(name) is being deinitialized")
}
Anyway, the book I am following wrote a code inside ViewController.swift. Beneath the viewDidLoad() method. Here are contents:
let person = Person(name: "randomName"); person.performAction();
The part I didn't understand is this: We initialize something with String. I get it but how does the class directly becomes able to use this? Like how does it know to take that init? I really didn't understand what happened there. It would be awesome if someone can explain the class and what happened in it.
Aucun commentaire:
Enregistrer un commentaire