Search code examples
objective-cnstableviewnsarraycontroller

Editing value in NSTableView results in error


I have an NSTableView whose column's values are bound to an NSArrayController. The problem is, when a user tries to edit values in the table (all the columns are editable), the program throws this error:

-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object

Anyone know how I can prevent this from happening? I can implement my own sloppy editor that will give the user a couple NSTextFields to create a new object for the NSArrayController whilst deleting the old one, but it would be much preferred if I could get this to work.

Thanks!


Solution

  • Is your table view's data stored in an NSDictionary, by any chance? Based on the error, it looks as though when the user edits a value, your code is attempting to set the new value on a key in an NSDictionary, like so:

    myDict[@"aKey"] = newValue;
    

    But this is impossible, since instances of NSDictionary are immutable. You could try using an NSMutableDictionary instead.