In our code we do the following:
- (void) createComment:(NSString *)comment ForId:(NSString *)objectId
{
[facebookArguments setObject:objectId forKey:FACEBOOK_COMMENTS_FOR_ID_KEY ];
[facebookArguments setObject:comment forKey:FACEBOOK_COMMENTS_FOR_ID_COMMENT];
[facebookPrefs writeToFile:facebookPrefsFilePath atomically: NO];
[facebookArguments writeToFile:facebookArgumentsFilePath atomically:NO];
}
but upon calling this code:
NSMutableDictionary* fbArgsDic = [[NSMutableDictionary alloc] initWithContentsOfFile: facebookArgumentsFilePath];
NSLog(@"Dictionary: %@", fbArgsDic);
Here’s the Log output before:
2011-08-04 16:11:53.938 My_App[30909:207] Dictionary: {
facebookGetCommentsForIdComment = Legend;
facebookGetCommentsForIdKey = 10150249987646875;
facebookLikeForIdKey = 10150249445616875;
}
And After:
2011-08-04 16:06:39.685 My_App[30693:207] Dictionary: {
facebookGetCommentsForIdComment = Legend;
facebookGetCommentsForIdKey = "1.015024998764688e+16";
facebookLikeForIdKey = 10150249445616875;
}
It’s converted the FACEBOOK_COMMENTS_FOR_ID_KEY entry, which was a NSString as seen above, into a NSNumber and lost some digits. These are LONG numbers as they are facebook id’s.
Any idea what’s going on and how we can fix it?
The dictionary should be getting serialized as a properly list, which should preserve types. Are you sure
idis really anNSStringto start with? (Also, I agree with other commenters that you should use a different variable name to avoid confusing with the typeid.)One possibility is that it’s actually an
NSDecimalNumber, which gets written out as a numeric type and parsed back in as anNSNumber, losing precision.Try this:
And if it is a numeric type after all, you can do: