07-18-2023, 02:30 PM
In WWDC 2014 session 403 [Intermediate Swift](
![enter image description here][1]
The speaker said in that case, if we don't use `[unowned self]` there, it will be a memory leak. Does it mean we should always use `[unowned self]` inside closure?
On [line 64 of ViewController.swift of the Swift Weather app](
[1]:
class TempNotifier {
var onChange: (Int) -> Void = {_ in }
var currentTemp = 72
init() {
onChange = { [unowned self] temp in
self.currentTemp = temp
}
}
}
[To see links please register here]
) and [transcript]([To see links please register here]
), there was the following slide![enter image description here][1]
The speaker said in that case, if we don't use `[unowned self]` there, it will be a memory leak. Does it mean we should always use `[unowned self]` inside closure?
On [line 64 of ViewController.swift of the Swift Weather app](
[To see links please register here]
), I don't use `[unowned self]`. But I update the UI by using some `@IBOutlet`s like `self.temperature` and `self.loadingIndicator`. It may be OK because all `@IBOutlet`s I defined are `weak`. But for safety, should we always use `[unowned self]`?[1]:
class TempNotifier {
var onChange: (Int) -> Void = {_ in }
var currentTemp = 72
init() {
onChange = { [unowned self] temp in
self.currentTemp = temp
}
}
}