По какой-то причине, когда я конвертирую эту строку NSString в целое число, я получаю совершенно случайное (но непротиворечивое) число.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
debtString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"String form: %@", debtString);
[receivedData release];
int debtInt = [debtString intValue];
NSLog(@"Integer form: %i", debtInt);
}
и это мой вывод на консоль:
2011-07-19 11:43:18.319 National Debt[50675:207] Succeeded! Received 14 bytes of data
2011-07-19 11:43:18.320 National Debt[50675:207] String form: 14342943000000
2011-07-19 11:43:18.320 National Debt[50675:207] Integer form: 2147483647
Если я поставлю точку останова в строке NSLog(@"Integer form: %i", debtInt);
и наведу курсор мыши на значение debtString
в строке выше, появится недопустимая сводка. Единственная причина, по которой я могу думать об этом, заключается в том, что я выпускаю debtString
до того, как он конвертируется, однако это явно не так.