Unix timestamp markup with RestKit on iOS

For an iOS application, I am working with RestKit. I need to parse the unix changed = "1325470840" timestamp in NSDate. I know that I can manually do this with

[NSDate dateWithTimeIntervalSince1970:1325470840]

But I use RestKits kernel data integration, and this is handled behind the scenes using date formats like below.

[RKObjectMapping addDefaultDateFormatterForString:@"E MMM d HH:mm:ss Z y" inTimeZone:nil];

Does anyone know how to create a date format to parse a unix timestamp? Or how can I analyze this with RestKit?

+5
source share
1 answer

, . RestKit № 141, , , , , . NSString > NSNumber > NSDate RestKit (# 503). , , .

- (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) {
            NSNumber *num = [NSNumber numberWithInt:[[newDict valueForKey:dateKey] intValue]];
            [newDict setValue:num forKey:dateKey];
        }
        [reformattedData addObject:newDict];
    }
    *mappableData = reformattedData;
}
+3

All Articles