views:

323

answers:

2

Can a Cocoahead please explain why UIView and it's sub classes don't adopt the NSCopying Protocol?

I can see, philosophically, why UITouch would not be copy compliant, as it's a very temporal object. By UIView, and it's subclasses, especially UIButton, seem like they should be able to be copied.

Certainly Apple has good reasons for doing things the way they do. Do you know their reason?

+5  A: 

It would seem the question they asked wasn't "Why not?" but "Why do it?" There's little point to doing so. There's rarely a need to copy a live view. Usually, template views are created through the NSCoding protocol (i.e. with Interface Builder), and that's about all a copyable view would be good for.

Chuck
A good example of when you'd want to make multiple copies of an object, like a view, is in UITableView when creating the dozen or so reuseable cells. Being able to copy one is much easier than multiple allocations of UIViews/UIButtons/UILabels, etc.
mahboudz
+1  A: 

Interesting question. In addition to Chuck's answer I wanted to add that the reason is possibly because Apple made that design decision... Just that simple; no real specific reason but that was the decision made.

I can also postulate that this decision might have been made because UIView is used as a subclass for a few other classes and the engineers didn't want to impose NSCopying forcefully on the subclasses.

Frank V