Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key-value validation does not allow value modification #565

Closed
jcanfield55 opened this issue Feb 23, 2012 · 1 comment
Closed

Key-value validation does not allow value modification #565

jcanfield55 opened this issue Feb 23, 2012 · 1 comment
Assignees
Milestone

Comments

@jcanfield55
Copy link

Thanks everyone who has created this great library. It is a big help!

I am having a problem with key-value validation. I want to modify the value of a date attribute because the RESTful API I am using returns dates in milliseconds since 1970 as a straight number (not the dotNet format). Since the mapping interprets this as a number, not a string, RESTKit won't call a custom date formatter. So I thought I'd solve the problem using key-value validation and modify the date back to the proper value.

My validator routine is called and creates the correct date, but RestKit does not use the new NSDate object I create. I checked it out in the debugger, and here is what is happening in RKObjectMappingOperation:

  • validateValue method gets the new date value, because it passed &value
  • but when validateValue returns control back to shouldSetValue, the new value is lost, because value was not passed by reference.

Here is the code I used for validation:

  • (BOOL)validateDate:(__autoreleasing id _)ioValue error:(NSError *__autoreleasing *)outError
    {
    if ([_ioValue isKindOfClass:[NSDate class]]) {
    NSDate* ioDate = ioValue;
    NSDate
    farFutureDate = [NSDate dateWithTimeIntervalSinceNow:(60.0_60_24_365_1000)]; // 1,000 years in future
    if ([ioDate laterDate:farFutureDate]==ioDate) { // if date is >1,000 years in future, divide time since 1970 by 1000
    NSDate* newDate = [NSDate dateWithTimeIntervalSince1970:([ioDate timeIntervalSince1970] / 1000.0)];
    *ioValue = newDate;
    }
    return YES;
    }
    return NO;
    } */

Thanks for your help, and I welcome any other suggestions besides key-value Validation for robustly handling milliseconds for dates.

John

@blakewatters
Copy link
Member

Thanks for the head's up here. I'll add a fix and test that ensures value modification is respected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants