Code for using custom types with the NSUserDefaults class.
Modified from the NSColor sample code on Apple’s developer web site
Source for NSUserDefaults+CocoaDevUsersAdditions.h :
#import <Foundation/Foundation.h>
@interface NSUserDefaults(CocoaDevUsersAdditions)
Source for NSUserDefaults+CocoaDevUsersAdditions.m :
#import “NSUserDefaults+CocoaDevUsersAdditions.h”
@implementation NSUserDefaults(CocoaDevUsersAdditions)
(void)encodeObject:(id
(id)decodeObjectForKey:(NSString)aKey { // Requires 10.2 or later for keyed archiving NSData theData = [self dataForKey:aKey]; return (theData != nil) ? [NSKeyedUnarchiver unarchiveObjectWithData:theData] : nil; } @end
Category:CocoaDevUsersAdditions