Skip to content

Instantly share code, notes, and snippets.

@stevenhuey
Created October 25, 2012 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenhuey/3953093 to your computer and use it in GitHub Desktop.
Save stevenhuey/3953093 to your computer and use it in GitHub Desktop.
After Mantle
@implementation CBCosmDatastream
#pragma mark - Mantle
+ (NSDictionary *)externalRepresentationKeyPathsByPropertyKey
{
return [super.externalRepresentationKeyPathsByPropertyKey mtl_dictionaryByAddingEntriesFromDictionary:@{
@"datastreamId": @"id",
@"updated": @"at",
@"value": @"current_value",
@"minValue": @"min_value",
@"maxValue": @"max_value"
}];
}
#pragma mark - KVC
- (void)setValue:(id)value forKey:(NSString*)key
{
if ([key isEqualToString:@"datapoints"])
{
if ([value isKindOfClass:[NSArray class]])
{
NSArray* values = (NSArray*)value;
NSMutableArray* datapoints = [NSMutableArray arrayWithCapacity:[values count]];
for (NSDictionary* attributes in values)
{
CBCosmDatapoint* datapoint = [[CBCosmDatapoint alloc] initWithAttributes:attributes];
[datapoints addObject:datapoint];
}
_datapoints = datapoints;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment