質問

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