RestKit/RestKit — Issue #503: Parsing Unix Timestamps sent as strings
Author: keisi
Created: 2012-01-12 21:05:41+00:00
State: open

I see that this issue was tackled in issue #141, but I am having a similar problem. I want to parse a unix timestamp but it is in the format of a string. While mapping objects, if it is a valid string can it be checked if it could be converted into an NSNumber and if it can can the parsing be done with the NSNumber > NSDate already done. So we end up with NSString > NSNumber > NSDate.

In the meantime I have solved this as follows

- (void)objectLoader:(RKObjectLoader *)loader willMapData:(inout id *)mappableData
{
NSArray *dateKeys = [NSArray arrayWithObjects:@"changed", nil];
NSMutableArray *reformattedData = [NSMutableArray arrayWithCapacity:[*mappableData count]];

for(id dict in [NSArray arrayWithArray:(NSArray*)*mappableData]) {
NSMutableDictionary* newDict = [dict mutableCopy];
for(NSString *dateKey in dateKeys) {
NSLog(@"%% : %@ %@", dateKey, [[newDict valueForKey:dateKey] mutableCopy]);
NSNumber *num = [NSNumber numberWithInt:[[newDict valueForKey:dateKey] intValue]];
[newDict setValue:num forKey:dateKey];
}
[reformattedData addObject:newDict];
}
*mappableData = reformattedData;
}