Question

I have a program where I save an int value as follows:

client.oldId = [clientDict objectForKey:@"oldId"];

At this point when debugging the value that is saved "supposely" is 31.

When I attempt to retrieve this item using the context, and i retrieve it as follows:

 int oldId = [NSNumber numberWithInt:client.oldId];

It becomes 174806944, why could this happen?, there are no summation operations or anything like that for this item and right before it saves to the context it is 31.

Any help would be appreciated.

Was it helpful?

Solution

set your variable to 0 before you set it

int oldId = 0
oldid = [NSNumber numberWithInt:client.oldId]; 

sometimes you can get garbage in a memory location that can cause this.

Updated Answer: Though technically sometimes I have found that if you dont clear out the integer I get the same thing. In this case he was setting an int to an NSNumber. The correct way was to take the NSNumber and get its integerValue like this:

[client.oldId intValue]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top