Search code examples
iosobjective-cxcodenslogunsigned-integer

unsigned int and unsigned long Xcode warnings in NSLogs


This is more of an annoyance than anything. Has anyone else run across this?

For debugging purposes, I'm spitting out the count of the _fetchedResults. Xcode gives me an unsigned int warning when I use %u, and then offers to change it to %lu.

enter image description here

OK Xcode, sure, go right ahead.

Then it immediately barks at me again with an unsigned long warning and offers to change it back %lu to a %u. And the cycle repeats. Of course, I can just delete the NSLog, but I'm using it during testing. And frankly it's more annoying than anything else.

enter image description here

Anyone else run across this before? Not sure how much it matters, but I'm on Xcode 7.3 with a deployment target of 9.0.x.


Solution

  • Check out this SO thread: Compile NSLog with unsigned int and unsigned long

    It says-

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

    And also says-

    The best way is NSLog(@"%lu", (unsigned long)array.count); for NSUInteger,
    and NSLog(@"%ld", (long)button.tag); for NSInteger: no warnings in either 32 bit or 64 bit.