Why does UIImageView own UIImage. Does it violate the principles of MVC?

One of the basic principles of MVC are never to represent your own data. This principle is repeated many times at WSDC Session 116. But why is UIImageView (view) its own UIImage (model)? Does this not violate the above principle?

Or do I understand nothing here? Maybe just because a UIImageView has an image property doesn't mean that it owns a UIImage ?

+6
source share
3 answers

The word own is often used simply to indicate that one object has saved another. Obviously, a view displaying an image should retain that image as long as it needs it. But this concept of "ownership" is very limited, and this does not mean that the representation should be responsible for storing, modifying or otherwise managing the image.

+7
source
Good question. In my opinion, UIImageView does not “own” UIImage, but obviously it needs to have a link to it. UIImageView does not create an image.

The same argument can be made for a UILabel (view) that has the text property (model).

+4
source

Technically, UIImageView does not have an image; it saves a link to a copy of the image in order to be able to display it effectively. UIImage just turns out to be unchanged, so the copy is the same instance as the original.

UILabel behaves the same, but explicitly declares its text property as copy .

+1
source

Source: https://habr.com/ru/post/908065/


All Articles