objective c - Core Data Integer changing value? -
i have problem core data storing integer (i chose int16 because have maximum of 6 signs).
my model holds
entity: 'expense' attribute in question is: @property (nonatomic, retain) nsnumber * month;
it automatically implemented nsnumber xcode (editor > createmanagedmodelsubclass)
month holds short identifier every month. example
201203 //would march of 2012
i store new entities snippet:
[newexpense setvalue:monthnumber forkey:@"month"];
which works fine. monthnumber has right value before store it.
i retrieve objects fetching method , store them in array called allexpenses
. array count true , have right amount of entities in it.
now this:
nsmutablearray *thismonthexpenses = [[nsmutablearray alloc]init ]; (expense *entity in allexpenses) { int tempmonth = [[entity month]intvalue]; if (tempmonth == month) { [thismonthexpenses addobject:entity]; } }
to filter out right entities belong current month.
month // integer holds encoded month (again: correctly!)
but somehow code:
int tempmonth = [[entity month]intvalue];
does not return 201203, strangly 4595 (always same value).
the same happens code:
for (expense *entity in monthexpenses) { if ([entity day].intvalue == todaynumber.intvalue) { //here entity day.intvalue returns wrong integer! [thisdayexpenses addobject:entity]; } }
i seem missing - cannot figure out what, tried around 2 hours , wrong int value after reading entities..
any ideas?
201203 0x311f3, while 4595 0x11f3 — what's happening is, you're losing significant byte. sounds in coredata have number set 16-bit integer, isn't capable of storing number want (16 bits can represent low 5 digits in decimal). should 32-bit integer.
Comments
Post a Comment