In one app I am working on I need to let the user edit a list of dates. I have those NSDate
objects in an array and bound that to a NSArrayController
. I bound a NSTableColumn
(the only column in a table view) to that array controller using the key path arrangedObjects.self
. This works fine - I get all the dates displayed in the table just the way I want it and I can add and remove dates.
The trouble is I can not edit the dates in the table. If I try I get an exception telling me, that NSDate
is not key-value-coding compliant to the key self
, which of course is true, there is no setSelf:
method.
I have two ideas how I could solve this:
- have my array not store
NSDate
directly but put it in anNSMutableDictionary
or some other object first. - not allow the user to edit the date directly but have him remove the wrong one and re-add the corrected date.
I don’t really like both solutions. I don’t like the first because I have to put stuff in my model just to get the GUI right. And the second is not very user-friendly.
So does anyone have an idea if there is a third and even better way to solve this?
Update: Temporary solution
For now I am using the table view’s data source to deal with this instead of using bindings. But I’d still like to see if there is a better solution using bindings for that problem, since I don’t really want to write a data source every time this (or a similar problem) turns up. It happens not just with NSDate
but all other value type classes provided by cocoa, even if they are mutable (like NSMutableString
).