One of the main principles of MVC is views should never own data. This principle is repeated many times in WWDC Session 116. But then why does UIImageView
(a view) own UIImage
(a model)? Doesn't it violate the above principle?
Or do I misunderstand anything here? Maybe just because UIImageView
has an image
property doesn't mean it owns that UIImage
?
The word own is often used just to indicate that one object has retained another. Obviously, a view that displays an image should retain that image for as long as it needs it. But this notion of "ownership" is very limited, and it doesn't mean that the view should be responsible for storing, changing, or otherwise managing the image.
Good question. In my opinion, the UIImageView does not "own" the UIImage, but it obviously needs to have a reference to it. The UIImageView does not instantiate the image.
The same argument could be made for a UILabel (a view) having a text property (a model).
Technically, a UIImageView
doesn't own an image, it keeps a reference to the image's copy to be able to render it efficiently. UIImage
just happens to be immutable, so a copy is the same instance as the original.
UILabel
behaves identically, but explicitly declares its text
property as copy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With