Question

I am getting this warnings when i open code in Xcode 5.1
"Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead" Why we need to cast NSInteger into long?

Was it helpful?

Solution

You get this warning if you compile on iOS (64-bit), because on that platform NSInteger is defined as long and is a 64-bit integer. The %i format, on the other hand, is for int, which is 32-bit. So the format and the actual parameter do not match in size.

Since NSInteger is 32-bit or 64-bit, depending on the platform, the compiler recommends to add a cast to long generally.

Update: Since iOS 7 supports 64-bit now as well, you can get the same warning when compiling for iOS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top