on my quest to be a smarter developer, i'm trying to learn how to remove as much redundant code as i possibly can.
i have several background colors the user may choose from... the code below only includes 2 (gray and white)... essentially i'm trying to pass the NSColor variable of each IBAction to the setNewDefaults method... unfortunately for me this code isn't working, as my variables are being passed as arguments (?) i though they would be...
thoughts?
i have several background colors the user may choose from... the code below only includes 2 (gray and white)... essentially i'm trying to pass the NSColor variable of each IBAction to the setNewDefaults method... unfortunately for me this code isn't working, as my variables are being passed as arguments (?) i though they would be...
Code:
- (IBAction)backgroundGray:(id)sender
{
NSColor *backgroundColor = [NSColor grayColor];
[self setBackgroundColors:[NSArray arrayWithObjects:backgroundColor, nil]];
[COLOR="Green"]// NSData *swatchBackgroundColorOBJECT = [NSKeyedArchiver archivedDataWithRootObject:backgroundColor];
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// [defaults setObject:swatchBackgroundColorOBJECT forKey:swatchBackgroundColorKEY];[/COLOR]
setNewDefaults(backgroundColor);
}
- (IBAction)backgroundWhite:(id)sender
{
NSColor *backgroundColor = [NSColor whiteColor];
[self setBackgroundColors:[NSArray arrayWithObjects:backgroundColor, nil]];
[COLOR="Green"]// NSData *swatchBackgroundColorOBJECT = [NSKeyedArchiver archivedDataWithRootObject:backgroundColor];
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// [defaults setObject:swatchBackgroundColorOBJECT forKey:swatchBackgroundColorKEY];[/COLOR]
setNewDefaults(backgroundColor);
}
- (void)setNewDefaults
{
NSData *swatchBackgroundColorOBJECT = [NSKeyedArchiver archivedDataWithRootObject:backgroundColor];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:swatchBackgroundColorOBJECT forKey:swatchBackgroundColorKEY];
}
thoughts?