Compile NSLog with unsigned int and unsigned long on iOS and OSX without warning

In iOS, NSUInteger has an unsigned int , on OSX it is an unsigned long . How can I make a print expression like

  NSLog(@"Array has %d elements.",[array count]); 

compile on both platforms without warning? I can, of course, use the #ifdef #else #endif construct, but this will add 4 lines of code. I could also pass the return value to an unsigned int. Is there a shorter solution?

+7
source share
2 answers

How about casting to the larger of the two?

 NSLog(@"Array has %ld elements.",(unsigned long)[array count]); 

There are no warnings on iOS, and I think this is not an OSX operating system.

+15
source

How about casting to the larger of the two?

 NSLog(@"Array has %ld elements.",(unsigned long)[array count]); No warning in iOS, and I think it a no-op in OSX. 
-one
source

All Articles