On Nov 30, 2008, at 3:35 PM, Alexander Cohen wrote:

Hi, Im getting the following line in the console when sending the 'removeObjectsAtArrangedObjectIndexes:' message to an NSArrayController instance.

-[NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object

I understand what it means but i'm not sure why it's happening. Is there anything i need to set up in order for the contents of the arrayController to be mutable?

The array controller is bound to a to-many property of some other object. That to-many property is not properly mutable.

You may be tempted to change that property's type from NSArray to an NSMutableArray, but that's not the right solution. The right solution is to implement the mutating indexed accessors for the property:

The minimal accessors for read access:
-countOf<Key>
-objectIn<Key>AtIndex:

One (or both) of the insertion methods:
-insertObject:in<Key>AtIndex:
-insert<Key>:atIndexes:

One (or both) of the removal methods:
-removeObjectFrom<Key>AtIndex:
-remove<Key>AtIndexes:

Optionally, for performance:
-get<Key>:range:
-replaceObjectIn<Key>AtIndex:withObject:


(Note, you can use an NSMutableArray as the backing store for the property, but that's different and separate from changing the type of the property to NSMutableArray. The latter violates encapsulation by allowing code outside of your class to modify the state of your objects without them being aware of it.)

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to