Should an NSString property under ARC be strong or copy?
Solution 1:
It is still recommended to copy because you want to avoid something passing a mutable string and then changing it without you knowing. A copy guarantees that the string you have will not change.
Solution 2:
Copying and ARC are orthogonal: you make copies of mutable objects to "freeze" their state; ARC keeps track of object's reference count.
NSString
objects may or may not be mutable. When you receive an NSString*
as a parameter, you cannot be certain that it is immutable unless you check its type (and even then you may get false positives). If your algorithm relies on the string not changing after being set, making a copy is the right thing to do. ARC, on the other hand, will ensure that the object is not released while you are holding a strong reference to it.
Solution 3:
It doesn't matter if you're using ARC or non-ARC.
The reasoning behind the copy
is so that you can guarantee that your class' internal state can't be modified from outside the implementation.
This could happen if someone passes you an NSMutableString
, and then modifies it later. That consideration is independent of the memory management environment.