Re: NSUserDefaults and non-property-list objects
Re: NSUserDefaults and non-property-list objects
- Subject: Re: NSUserDefaults and non-property-list objects
- From: Larry Gerndt <email@hidden>
- Date: Wed, 15 Jun 2005 14:56:35 -0700
Well (blush), I just realized that what I referred to as "the code that does the conversion" is, at least in my case, always the same single line: "[NSKeyedArchiver archivedDataWithRootObject:object]", so I can just use that when setting up the defaults dictionary, and use the NSUserDefaults+Extensions category methods for when the user changes their prefs.On Jun 15, 2005, at 2:23 PM, Larry Gerndt wrote: Apple documentation points out that although NSUserDefaults object support extends only to property list types (NSData, NSNumber, NSArray, etc), one can easily add a category to NSUserDefaults and define methods therein to support converting other types (such as NSColor) to NSData. But if I use this technique, how do I go about creating a dictionary of these non-standard defaults that can be passed to registerDefaults:? The methods that do the conversions to NSData are in the category of NSUserDefaults, not NSMutableDictionary, so it would appear I would have to duplicate those methods elsewhere to be able to do the conversions
One possible solution I can think of is: instead of putting the conversion code into the NSUserDefaults+Extensions methods, I could add a category to each class type that needs converting, for example an NSColor+Extensions method: -(NSData*)colorAsData; Then that could be used both when creating items for the defaults dictionary and also be used by the NSUserDefaults+Extensions category methods. Is that a sensible approach?
-- Larry Gerndt AIM Handle: SonOfTheSonOfMan Let the truth be told though the heavens fall -- James Garrison -- Larry Gerndt AIM Handle: SonOfTheSonOfMan Let the truth be told though the heavens fall -- James Garrison |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden