Thanks for all of the responses. After some monkeying around, I figured out that I'd used an NSNumber where I should have used an NSString. The code is now compiling and running happily.

While I did learn some things from this, I'm confused about NSUserDefaults and the values it can store. I created an NSMutableDictionary to register the defaults, which is, I believe archived as a property list. Floats can be associated with NSString keys and stored in dictionaries, and there are methods for floatForKey: and setFloat: forKey: so, storing floats in a dictionary is supported, but, according to my understanding of Apple's documentation, I can't archive floats in a property list. I thought that I needed to transform the float into an NSNumber before saving to NSUserDefaults, and then transform the NSNumber to a float before I could use it to set the gradient angle.

In Introduction to User Defaults, Apple states:

The NSUserDefaults class only supports the storage of objects that can be serialized to property lists. This limitation would seem to exclude many kinds of objects, such as NSColor and NSFont objects, from the user default system. But if objects conform to the NSCoding protocol they can be archived to NSData objects, which are property list– compatible objects. For information on how to do this, see “Storing NSColor in User Defaults“; although this article focuses on NSColor objects, the procedure can be applied to any object that can be archived.


In the Property List Programming Guide, Apple states:

If a property list object is a container (an array or dictionary), all objects contained within it must also be supported property list objects. (Arrays and dictionaries can contain objects not supported by the architecture, but are then not property lists, and cannot be saved and restored with the various property list methods.) Moreover, although dictionary keys in NSDictionary and CFDictionary are defined to be an object of any type, for property lists they must be string objects.

Cocoa property lists organize data into named values and lists of values using these classes:

NSArray
NSDictionary
NSData
NSString (java.lang.String in Java)
NSNumber (subclasses of java.lang.Number in Java)
NSDate

What am I not getting?

Looking forward to not having to prefix my posts with "Newb Question"...

Brad


On Aug 29, 2008, at 9:07 PM, Graham Cox wrote:


On 30 Aug 2008, at 2:04 pm, Graham Cox wrote:

You can really tell


I meant of course that you CAN'T really tell...

G.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to