Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active August 29, 2015 13:57
Show Gist options
  • Save akhenakh/9442985 to your computer and use it in GitHub Desktop.
Save akhenakh/9442985 to your computer and use it in GitHub Desktop.
Mantle conversion for timestamped json
+ (NSValueTransformer *)publictionDateJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *timestamp, BOOL *success, NSError **error){
return [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
} reverseBlock:^(NSDate *date, BOOL *success, NSError **error) {
return [NSNumber numberWithDouble:[date timeIntervalSince1970]];
}];
}
@Flanker4
Copy link

Please fix gist

 return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSNumber *timestamp) {
        return [NSDate dateWithTimeIntervalSince1970:[timestamp doubleValue]];
    } reverseBlock:^(NSDate *date) {
        return  [NSNumber numberWithDouble:[date timeIntervalSince1970]];
    }];

@akhenakh
Copy link
Author

akhenakh commented Jun 1, 2015

thx

@akhenakh
Copy link
Author

akhenakh commented Jun 1, 2015

updated with new transformerUsingForwardBlock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment