• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArrayController trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController trouble


  • Subject: Re: NSArrayController trouble
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 1 Dec 2008 04:07:14 -0600

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@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Core Data vector modeling query
  • Next by Date: [MEET] CocoaHeads Frankfurt, TONIGHT 8PM
  • Previous by thread: Re: Core Data vector modeling query
  • Next by thread: [MEET] CocoaHeads Frankfurt, TONIGHT 8PM
  • Index(es):
    • Date
    • Thread