문제

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