you usually want to declare a copy of the property in this case.
in most cases, immutable collectors should be copied, not saved. many people make mistakes and end up writing a lot of copies by hand and exchange objects that should not be shared, thinking that they are doing everything well by cutting a corner.
copying in this form (collection) shallow. objects in the array are not copied, but only the distribution of the array.
a good implementation of an immutable collection can simply implement a copy while preserving the self. if the argument is changed, you want to get a copy anyway (in most cases).
your program is then simplified to an announcement:
// note: copy, not retain. honor this if you implement the accessors. @property (nonatomic, copy) NSArray * foodLocations;
and then the setter:
self.foodLocations = [self returnOtherArray];
Of course, you should still initialize, dealloc, and properly manage streaming security.
luck
justin
source share