• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSColorWell and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSColorWell and bindings


  • Subject: Re: NSColorWell and bindings
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 10 Jun 2009 15:27:26 -0700


On 2009 Jun 10, at 13:16, Lorenzo Thurman wrote:

NSColor * color = [NSColor selectedMenuItemColor];

[defaults setObject:[NSArchiver archivedDataWithRootObject:color] forKey:
@"textColor"];


NSData * colorData = [defaults objectForKey:@"textColor"];


// Other default values


[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues
:defaults];



There is a Data value in the preferences file, so there must be something
else going on.

Storing a color in user defaults is something you'd expect to be easy but is not. I wrote a little category that helps, but if I recall correctly there are a few other hoops you need to jump through to make it work with bindings. Anyhow they're all explained in the link to apple.com given below. Read that whole web page and do what it says.


#import <Cocoa/Cocoa.h>


/*! @brief

 @details  The NSColor methods were copied from
 http://developer.apple.com/documentation/Cocoa/Conceptual/DrawColor/Tasks/StoringNSColorInDefaults.html
*/
@interface NSUserDefaults (MoreTypes)

- (void)setColor:(NSColor*)aColor
          forKey:(NSString*)aKey ;

- (NSColor*)colorForKey:(NSString*)aKey ;

@end

@implementation NSUserDefaults (MoreTypes)

- (void)setColor:(NSColor *)aColor forKey:(NSString *)aKey {
    NSData* theData = [NSArchiver archivedDataWithRootObject:aColor] ;
    [self setObject:theData forKey:aKey] ;
}

- (NSColor*)colorForKey:(NSString *)aKey {
NSColor* theColor = nil ;
NSData* theData = [self dataForKey:aKey] ;
if (theData != nil) {
theColor = (NSColor*)[NSUnarchiver unarchiveObjectWithData:theData] ;
}


    return theColor ;
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSColorWell and bindings (From: Lorenzo Thurman <email@hidden>)
 >Re: NSColorWell and bindings (From: Alexander Spohr <email@hidden>)
 >Re: NSColorWell and bindings (From: Lorenzo Thurman <email@hidden>)

  • Prev by Date: App does not start on a different machine
  • Next by Date: Re: App does not start on a different machine
  • Previous by thread: Re: NSColorWell and bindings
  • Next by thread: Re: NSColorWell and bindings
  • Index(es):
    • Date
    • Thread