How can I get didSet to recognize when imageView.image has been set? It only seems to be called during initialization.
@IBOutlet weak var imageView: UIImageView! {
didSet {
//do stuff
}
}
How can I get didSet to recognize when imageView.image has been set? It only seems to be called during initialization.
@IBOutlet weak var imageView: UIImageView! {
didSet {
//do stuff
}
}
Copyright © 2021 Jogjafile Inc.
didSetwill only be called when you set theimageViewitself. For example:This doesn't really make sense, since you already have an image view and it's working completely fine. What you're trying to do is to monitor changes in one of your image view's properties.
To do this, try making a subclass of
UIImageView, then observing changes in itsimage. Don't forget to set the custom class of your image view back in the storyboard, then reconnecting the outlet.If you need to execute some code back in your view controller, try using a closure.
Alternatively, you can use KVO.