Created
February 6, 2013 22:40
-
-
Save bdittmer/4726569 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "ESGroupIncentive.h" | |
NSString *giIdKey = @"id"; | |
NSString *giJobIdKey = @"job_id"; | |
NSString *giPercentCompleteKey = @"percent_complete"; | |
NSString *giPercentReservedKey = @"percent_reserved"; | |
NSString *giGoalsKey = @"goals"; | |
NSString *giRewardsKey = @"rewards"; | |
@interface ESGroupIncentive() | |
+ (NSDictionary *)valueMap; | |
@end | |
@implementation ESGroupIncentive | |
+ (ESGroupIncentive *)fromDictionary:(NSDictionary *)d { | |
ESGroupIncentive *gi = [[ESGroupIncentive alloc] init]; | |
NSDictionary *valueMap = [self valueMap]; | |
for (NSString *key in valueMap) { | |
if (d[key]) [gi setValue:d[key] forKey:valueMap[key]]; | |
} | |
return [gi autorelease]; | |
} | |
- (id)copyWithZone:(NSZone *)zone { | |
ESGroupIncentive *gi = [[ESGroupIncentive allocWithZone:zone] init]; | |
NSArray *values = [[ESGroupIncentive valueMap] allValues]; | |
for (NSString *value in values) { | |
[gi setValue:[[[self valueForKey:value] copy] autorelease] forKey:value]; | |
} | |
return gi; | |
} | |
- (void)encodeWithCoder:(NSCoder *)aCoder { | |
NSDictionary *valueMap = [ESGroupIncentive valueMap]; | |
for (NSString *key in valueMap) { | |
[aCoder encodeObject:[self valueForKey:valueMap[key]] forKey:key]; | |
} | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder { | |
self = [super init]; | |
NSDictionary *valueMap = [ESGroupIncentive valueMap]; | |
for (NSString *key in valueMap) { | |
[self setValue:[aDecoder decodeObjectForKey:key] forKey:valueMap[key]]; | |
} | |
return self; | |
} | |
+ (NSDictionary *)valueMap { | |
return @{giIdKey:@"_groupIncentiveId", giJobIdKey:@"_jobId", giPercentCompleteKey:@"_percentComplete", | |
giPercentReservedKey:@"_percentReserved", giGoalsKey:@"_goals", giRewardsKey:@"_rewards"}; | |
} | |
- (void)dealloc { | |
[_groupIncentiveId release]; | |
[_jobId release]; | |
[_percentComplete release]; | |
[_percentReserved release]; | |
[_goals release]; | |
[_rewards release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment