What's the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?

cocoa, iphone, macos, objective-c, properties

Solution

As said before, the right way to do it is not to make the mutable array a property. There's a great explanation of what you should implement to be KVC compliant here.

Problem

I have an Obj-C 2.0 class that has an NSMutableArray property. If I use the following code, then the synthesised setter will give me an immutable copy, not a mutable one: ``` @property (readwrite, copy) NSMutableArray *myArray; ``` Is there any reason that Apple didn't implement the following syntax? ``` @property (readwrite, mutablecopy) NSMutableArray *myArray; ``` Since we don't have `mutablecopy`, what's the best way to handle this (seemingly common) situation? Should I just write my own setter that does a -mutableCopy?

Original source

Related problems