ios - Returning copy of object -
i can't understand difference between these 2 bits of code, behave same way.
- (nsarray *)handleimages { nsmutablearray *images = [nsmutablearray new]; //...do array.. return [images copy]; } - (nsarray *)handleimages { nsmutablearray *images = [nsmutablearray new]; //...do array.. return images; }
the method set return immutable array. first version converts mutable array creates immutable array before returning it. second version returns mutable array. first version little cleaner, since caller expects immutable array.
Comments
Post a Comment