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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -