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 14:42:51 -0500
On Feb 5, 2004, at 9:06 AM, Yann Bizeul wrote:
Helo list.
A couple of questions about this obscure thing named ObejctController
that seem to be not so used at this time.
Two concrete cases we have problem to use :
First one :
-------------
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.
Second one :
-----------------
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).
There was discussion about this a couple of months ago with other
solutions... check cocoa.mamasam.com for NSUserDefaultsController for
more details.
Conclusion
---------------
What's the point of NSUserDefaults with NSArrayController ? Is there
a way to make them work together ?
--
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.
_______________________________________________
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.