Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Last active December 17, 2015 23:39
Show Gist options
  • Save atomkirk/5690707 to your computer and use it in GitHub Desktop.
Save atomkirk/5690707 to your computer and use it in GitHub Desktop.
Copying + mutable = @Property (copy)

I've been told about this, but it's never bitten me, until today. So, get in the habit:

http://stackoverflow.com/questions/387959/nsstring-property-copy-or-retain

He says immutable and I'm not sure I understand why, but it's clear why you would do this with mutable. UPDATE: he says immutable, implying mutable too, because it's entirely possible to assign an immutable version of an object to a property specified as mutable, so it's not safe to assume that just because the property is NSArray doesn't mean it isn't a mutable array and some statement somewhere isn't changing it's content's behind your back.

One interesting thing to note: if you assign an immutable NSArray to a @property (copy, nonatomic) NSArray *array it will actually retain it, not copy it. So it's is smart enough to just retain rather than copy it when it really is immutable, saving an allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment