Re: NSArrayController, custom objects, user defaults
Re: NSArrayController, custom objects, user defaults
- Subject: Re: NSArrayController, custom objects, user defaults
- From: Scott Anguish <email@hidden>
- Date: Thu, 5 Feb 2004 16:05:43 -0500
On Feb 5, 2004, at 3:50 PM, Yann Bizeul wrote:
>
>>
>
>> 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
you have to convert it to an NSData object using the value
transformer... that's done by encoding it with an NSValueTransformer..
That conversion is done by archiving it to the NSData using NSCoder.
if you need more info, I can help offline.
>
>
>> 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
>
If you need to make it multi-level deep, you'll need to make a deep
mutable transformer.
>
> 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 :-/
>
Well, I'm not sure that the staff there would be up on
NSUserDefaultsController... it's new, and these are interesting
situations that we need to document (and I've made a note for my
docplan for this to include it)
Contact me offline, and we can trudge through this. Documentinging
this is my responsibility, so understanding your problems will ensure
that I get the docs the way others need them.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.