Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 355
Louis Nguyen Avatar asked Feb 09 '12 17:02

Louis Nguyen


3 Answers

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.

like image 107
Caleb Avatar answered Nov 15 '22 07:11

Caleb


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).

like image 41
picciano Avatar answered Nov 15 '22 08:11

picciano


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.

like image 42
Costique Avatar answered Nov 15 '22 07:11

Costique