Depends on how much you need to defend.
There is no sensible way a client of your code can check for volatility. Thus, there is no sensible way in which a client can drop from NSString to NSMutableString and unexpectedly achieve non-compiler-warning variability for the string.
So, as long as you trust your customers, you can also return a mutable string (like NSString ). Even if the client does something stupid and mutates, the compiler warnings will be damned, nothing will break.
In cases where this is important, you are returning the mutable backup storage of some object that should not be mutated externally. In this case, the client can ignore compiler warnings and / or pass it in a mutable version and completely crop your object.
Or, more subtly, a client can get a link to a supposedly unchanged return type and hold it long enough to mutate later, leaving their link in an amazing state.
Best practice: when calculating and returning a transition value, volatility does not matter. When returning links to an internal mutable store, it is best to make an immutable copy.
source share