I have a class that handles a lot of defaults, here is how I initialize the defaults:
+ (void) initialize
{
NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
NSData* colorData= [NSKeyedArchiver archivedDataWithRootObject: [NSColor orangeColor]];
NSDictionary* def= @{ @"colorKey" : colorData, ... };
[defaults registerDefaults: def];
}
Then I make available one method for reading the default color and one method for setting it:
- (NSColor*) color
{
NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
NSData* colorData= [defaults objectForKey: colorKey];
return [NSKeyedUnarchiver unarchiveObjectWithData: colorData];
}
- (void) setColor: (NSColor*) color
{
NSUserDefaults* defaults=[NSUserDefaults standardUserDefaults];
NSData* colorData= [NSKeyedArchiver archivedDataWithRootObject: color];
[defaults setObject:colorData forKey: colorKey];
}
But if inside the color: method I print the color, sometimes it's of class NSColorWell and it creates troubles inside the application.
NSColorWell
is an NSControl
according to https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSColorWell_Class/Reference/Reference.html, so it looks like that you are mistakenly calling setColor:
with NSColorWell
instance instead of NSColor
.