Skip to content

Instantly share code, notes, and snippets.

@bdittmer
Created February 6, 2013 22:40
Show Gist options
  • Save bdittmer/4726569 to your computer and use it in GitHub Desktop.
Save bdittmer/4726569 to your computer and use it in GitHub Desktop.
#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