On some intuitive (perhaps wrong) idea of performance, I always get a copy of a mutable instance before I store it. So if a property expects an NSArray I take the mutable array I’m working with and store it as self.array = mutableArray.copy (though the property is specified as strong or retain).
This seems silly to me, suddenly, but is it? Do mutable instances — doing the exact same task — perform the same?
Note: The mutable instance falls out of scope and (thanks to ARC) gets released right after this, so there’s no worry that it’ll be mutated once it’s assigned to the property.
NSArrayandNSMutableArrayare both (as far as I’m aware) implemented on top of CFArray, which simply has a flag specifying whether it’s mutable.CFArrayfunctions which require a mutable array have an assertion right at the beginning, checking that flag:Mutable and immutable
CFArrays are identical other than passing or failing this assertion, and so shouldNSArrays andNSMutableArrays be, performance- or other-wise.