Why does an NSInteger variable have to be cast to long when used as a format argument?
问题 NSInteger myInt = 1804809223; NSLog(@"%i", myInt); <==== The code above produces an error: Values of type "NSInteger" should not be used as format arguments: add an explicit cast to 'long' instead. The correct NSLog message is actually NSLog(@"%lg", (long) myInt); Why do I have to convert the integer value of myInt to long if I want the value to display? 回答1: You get this warning if you compile on OS X (64-bit), because on that platform NSInteger is defined as long and is a 64-bit integer.