3

This problem appears to be affecting a lot of objective-c developers working with custom built restful APIS -- like here and here. On the backend we are using ISO 6801 dates, and I've had trouble getting a valid date when I pull objects down from the server. This is the date format we use, but NSDate can't recognize it because the colon in the time zone offset:

1981-09-01T00:00:00-06:00

I've tried using this ISO6801 parser and unparser, which is included in the latest version of RestKit, but I can't figure out how to successfully add it to the object mapping. How do I add a date formatter to a RestKit objectmapping? Can anyone provide a code sample of how to do this?

Here is my failed code. This is what I'm looking for and tried based on a google groups post, but it gives errors:

[mapping.dateFormatStrings addObject:[[MyISO8601DateFormatter] alloc] init]];

There's a related answer on this post, but it is partly outdated and lacks a working example.

Community
  • 1
  • 1
Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
  • To use non-ARC code in an ARC project, see [here](http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project). In fact, RestKit itself is not ARC compliant. – Paul de Lange Aug 01 '12 at 06:35
  • Thanks. Got that working just fine, still have the same problems of adding the date formatter to the RestKit object mapping. – Kyle Clegg Aug 01 '12 at 15:14

1 Answers1

1

To add a date formatter you do this:

[RKObjectMapping addDefaultDateFormatter: formatter];

If that flavor doesn't suit you, you can try some of the other options you will see there in the header file.

Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
  • Thanks -- that will do it globally. I was wondering how to add it to a particular mapping, but I just figured that part out too. You have throw the date formatter into an array as in: mapping.dateFormatters = [NSArray arrayWithObject: isoDateFormatter];. – Kyle Clegg Aug 01 '12 at 15:55