I am trying to understand why the same function causes a memory leak if I call it from viewDidAppear rather than viewWillLayoutSubiews.
I have two extensions that fits the sublayers of a view to its bounds:
extension CALayer {
func fit(rect: CGRect) {
frame = rect
sublayers?.forEach { $0.fit(rect: rect) }
}
}
extension UIView {
func fitLayers() {
layer.fit(rect: bounds)
}
}
And the same call priorityButton.fitLayers()
from viewDidAppear doesn't deallocate the Layer objects. Both do the job as expected and works well but I'd like to understand why is it.
Thanks!