magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.8k forks source link

int64 parsed incorrectly #1291

Open thebaotran opened 7 years ago

thebaotran commented 7 years ago

When integrating with the Facebook API to get my friend's UID, they are returned as ints and I'm storing them as int64 in Objective-C (longlong). I'm calling MR_importFromArray which eventually calls: MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData. It eventually hits this block of code: https://github.com/magicalpanda/MagicalRecord/blob/3560a8c628101eb0810e55295234106d9eb7ef36/MagicalRecord/Categories/DataImport/NSAttributeDescription%2BMagicalDataImport.m#L48-L57

The error occurs in MR_numberFromString when converting the value to a double: [NSNumber numberWithDouble:[value doubleValue]];

Specifically, my test value is 10158365420975381 and this function is returning 10158365420975380. There are other values that are off by 1 as well.

I've fixed this issue by storing the value as a string instead, but if wanting to store as an int, this will cause problems.

Coeur commented 5 years ago

You need to store them as NSNumber instead of NSValue. If you properly box @10158365420975381 when storing, then the condition ![value isKindOfClass:[NSNumber class]] will not match and it will not call MR_numberFromString.