I'm actually working with Realm Objective-C, here is my problem:
I have a webservice which return this:
{
"id": 1,
"name": "Project 1",
"summary": "",
"description": "description project 1 ...",
"amountTargeted": 0,
"amountReached": 0,
"beginDate": 1432044917000,
...
...
}
When I try to parse the response using this method:
[Project createOrUpdateInDefaultRealmWithValue:projectDictionary];
I have this error:
'RLMException', reason: 'Invalid value '0' for property 'amountReached''
In my model of project I declared amourReached like that:
@property NSInteger amountReached;
I did some tests, and this problem appears only for value is zero.
I think the problems come from this method who return false when it's zero:
static inline bool nsnumber_is_like_integer(NSNumber *obj)
{
const char *data_type = [obj objCType];
// FIXME: Performance optimization - don't use strcmp, use first char in data_type.
return (strcmp(data_type, @encode(short)) == 0 ||
strcmp(data_type, @encode(int)) == 0 ||
strcmp(data_type, @encode(long)) == 0 ||
strcmp(data_type, @encode(long long)) == 0 ||
strcmp(data_type, @encode(unsigned short)) == 0 ||
strcmp(data_type, @encode(unsigned int)) == 0 ||
strcmp(data_type, @encode(unsigned long)) == 0 ||
strcmp(data_type, @encode(unsigned long long)) == 0);
}
Note : I add a breakpoint and try some log:
(lldb) p number
(NSNumber *) $6 = 0x15e76f50 @"0"
(lldb) po number
0
(lldb) p nsnumber_is_like_integer(number)(why ???)
(bool) $3 = false
(lldb) p nsnumber_is_like_integer(@0)(Why different of the first ?)
(bool) $5 = true
(lldb) p nsnumber_is_like_integer(@1)
(bool) $4 = true
Thanks in advance if you have any idea, is it a realm problem or a problem from my code ?