You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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:
Here is the code I used for validation:
{
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
The text was updated successfully, but these errors were encountered: