Created
May 7, 2010 18:23
-
-
Save vickeryj/393816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "NSObject+PropertySupport.h" | |
@interface PropertyCoder : NSObject <NSCoding> { | |
} | |
@end | |
-- | |
#import "PropertyCoder.h" | |
#define PROPERTY_KEY_PREFIX @"PCPropertyKeyPrefix" | |
@implementation PropertyCoder | |
#pragma mark NSCoding methods | |
- (void)encodeWithCoder:(NSCoder *)aCoder { | |
for (NSString *propertyKey in [[self class] propertyNames]) { | |
id propertyValue = [self valueForKey:propertyKey]; | |
if ([propertyValue conformsToProtocol:@protocol(NSCoding)]) { | |
[aCoder encodeObject:propertyValue forKey:[PROPERTY_KEY_PREFIX stringByAppendingString:propertyKey]]; | |
} | |
} | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder { | |
self = [super init]; | |
for (NSString *propertyKey in [[self class] propertyNames]) { | |
[self setValue:[aDecoder decodeObjectForKey:[PROPERTY_KEY_PREFIX stringByAppendingString:propertyKey]] forKey:propertyKey]; | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment