5 ms·
> @property (retain) NSString *title; Why is he retaining NSString? Shouldn't that be (copy)?
by chime 16y ago
> @property (retain) NSString *title;
Why is he retaining NSString? Shouldn't that be (copy)?
- msbarnett 16y agoNot necessarily. If you want to avoid situations where title points at a mutable subclass, yes, but if that isn't a concern, there's nothing inherently incorrect with a simple retain.
- ajg1977 16y agoExcept that if someone modifies the string they passed you, your 'copy' of the string will also change.
- naz 16y agoThat would only occur if it was an NSMutableString, like the GP said.
- jckarter 16y ago"copy"ing an immutable string just retains it, so there's little benefit to using a retain property for NSString properties, or for properties of the other NSMutableCopying type families. As a best practice you should always use copy properties for them.