I haven't thought about it much until today. Basically I'm in a situation in which I have the same UIImage appear multiple times in my ViewControllers, and I'm not sure what the impact is.
class MyObjectA{
private(set) var myName: String
var myImage: UIImage? { UIImage(named: myName) } //as computed property
}
class MyObjectB{
private(set) var myName: String
private(set) var myImage: UIImage? //as stored property
init(myName: String){
self.myName = myName
self.myImage = UIImage(named: myName)
}
}
Consider a TableView, where each cell corresponds to an object. Is it bad having an image constantly being instantiated with myimageview.image = UIImage(named: myobject.imagename) versus just instantiating once and referencing it with myimageview.image = myobect.image ? Or does Swift do some super magic where it optimizes it under the hood, knowing that image was already loaded once?