Please considering following code:
class myManager {
var aView: UIView!
func createView() {
aView = UIView()
}
func removeView() {
aView = nil // anything else?
}
}
If I create a UIView
like this and later I want to remove it, is this the correct way? Anything I should be aware of?
In order to have
aView
to be deinitialised and removed from memory you need to make it unreferenced by anything that keeps a strong reference to it. That means it should not be referenced by any part of your code, and by the UIKit view stack.In your case it might look like this:
On a side note, if you are removing the view, then you probably should not use
var aView: UIView!
but insteadvar aView: UIView?
.