views:

120

answers:

2

Any idea from a code design standpoint why the internal implementation of UITextView uses string but not mutable string when its content is meant to change often?

+2  A: 

From a general coding point of view:

When setting a property the property setter method is called. That way the control is able to notice when the property is changed, so that it can redraw the control with the new content.

If the property is a mutable object, you can change it's contents and the control will not get any notification that this has happened, so it doesn't know that the control needs to be redrawn.

Guffa
A: 

It's a general pattern in Cocoa to pass around immutable objects instead of allowing outside classes access private mutable variables. You'll see the same thing with collections classes like NSArray and NSDictionary.

Marc Charbonneau