Re: NSArrayController, custom objects, user defaults
Re: NSArrayController, custom objects, user defaults
- Subject: Re: NSArrayController, custom objects, user defaults
- From: Yann Bizeul <email@hidden>
- Date: Thu, 5 Feb 2004 21:50:00 +0100
>
> Use NSArrayController to store custom classes, and store them into
>
> NSUserDefaults.
>
> There is no problem using NSArrayController to manage custom
>
> objects, once the application is launched, I can add, delete, and
>
> manager object properties via different kind of controls.
>
> But as soon as I want to store this into NSUserDefaults, I get this
>
> error :
>
>
>
> -[NSKeyValueSlowMutableArray bytes]: selector not recognized
>
>
>
> NSKeyValueSlowMutableArray is unknown to me, seem to be a private
>
> class, and I did not find a solution to this, I tried to make my
>
> class NSCodr womplient without sucess.
>
>
>
>
You can't store custom objects in user defaults without encoding
>
them.. You'd need to use the value transformer that
>
archives/unarchives them to NSData.
As I said, I tried to make it NSCoder complient without success. In
fact I thought value transformer were for another level in the
hierarchy : Not for the whome object itself, but for their instance
variable (that will be used as "key" in bindings. I don't know if I'm
clear :
_______ 1 _______ ______ 2 ______ _ 3 __
NSArrayController -> myCustomObject1 -> aValue
-> myCustomObject2 -> aValue
According to me, NSValueDecoder is to decode level 3 variables, not
whole objects in level 2. So am I wrong, or is there a solution to
archive/unarchive level 2 objects in the NSArrayController
>
> Almost the same, but without a custom object, just an
>
> NSMutableDictionary as my NSArrayController's "Object class Name"
>
> (this is the default). This time, I can create (add) objects, but not
>
> modify properties, I get a :
>
>
>
> -[NSCFDictionary setObject:forKey:]: mutating method sent to
>
> immutable object
>
>
>
> and this is absolutely unusable. Preferences are saved, since when I
>
> re-open the application, I get each time one more epty object in the
>
> tableview I binded to the NSArrayController.
>
>
>
>
Items that are read from user defaults are not mutable. You'd need
>
to either use a value transformer to make a deep mutable copy, or some
>
other technique. This is only an issue with user defaults when you
>
read complex data types back (so, NSArray, NSDictionary).
I had this error when trying to set up a simple string in a TextField,
that's the whole dictionary in the level 2 that seem to be immutable,
so then, we are in the same situation as case 1, I don't see a way to
encode/decode level 2
>
There was discussion about this a couple of months ago with other
>
solutions... check cocoa.mamasam.com for NSUserDefaultsController for
>
more details.
We spent three days at the Linux Solutions exhibition with Apple's
staff here to debug this problem without success, and found no
solutions in the archives :-/
Thank you
--
Yann Bizeul - yann at tynsoe.org
http://projects.tynsoe.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.