| Line | |
|---|
| 1 | #import "NSUserDefaults.h" |
|---|
| 2 | |
|---|
| 3 | @implementation NSUserDefaults (ColorSupport) |
|---|
| 4 | - (void)setColor:(NSColor *)aColor forKey:(NSString *)aKey |
|---|
| 5 | { |
|---|
| 6 | NSData *theData=[NSArchiver archivedDataWithRootObject:aColor]; |
|---|
| 7 | [self setObject:theData forKey:aKey]; |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | - (NSColor *)colorForKey:(NSString *)aKey |
|---|
| 11 | { |
|---|
| 12 | NSColor *theColor=nil; |
|---|
| 13 | NSData *theData=[self dataForKey:aKey]; |
|---|
| 14 | if (theData != nil) |
|---|
| 15 | theColor=(NSColor *)[NSUnarchiver unarchiveObjectWithData:theData]; |
|---|
| 16 | return theColor; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | - (void)setColorsWithDictionary:(NSDictionary *)colors forKey:(NSString *)aKey |
|---|
| 20 | { |
|---|
| 21 | NSMutableDictionary *data = [NSMutableDictionary dictionary]; |
|---|
| 22 | for(NSString *key in colors) { |
|---|
| 23 | [data setObject:[NSArchiver archivedDataWithRootObject:[colors objectForKey:key]] forKey: key]; |
|---|
| 24 | } |
|---|
| 25 | [self setObject:data forKey:aKey]; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | - (NSDictionary *)colorsDictionaryForKey:(NSString *)aKey |
|---|
| 29 | { |
|---|
| 30 | NSDictionary *data = [self dictionaryForKey:aKey]; |
|---|
| 31 | if(data != nil) { |
|---|
| 32 | NSMutableDictionary *colors = [NSMutableDictionary dictionary]; |
|---|
| 33 | for(NSString *key in data) { |
|---|
| 34 | [colors setObject:(NSColor *)[NSUnarchiver unarchiveObjectWithData:[data objectForKey:key]] forKey: key]; |
|---|
| 35 | } |
|---|
| 36 | return colors; |
|---|
| 37 | } else { |
|---|
| 38 | return nil; |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | @end |
|---|