I am fetching data from the web, and I am having problems with the numbers that are returned. For example, when the int 1 is returned from the server, and I try and convert that int to a NSNumber, the value of the NSNumber is 151241152. The number is slightly different every time, but it is always over 1 billion. Here is my code:

int agrees = (int)[info objectForKey:kWaveAgrees];
wave.numberOfAgrees = [NSNumber numberWithInt:agrees];

Does anyone know why this is happening?

有帮助吗?

解决方案

NSNumber is an object. You cannot cast it into an int, it must be unboxed first.

int agrees = [[info objectForKey:kWaveAgrees] intValue]; 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top