How to log an long long value with NSLog?

Viewed 25632

How can I do that? What's the format specifier?

For example, I have:

long long veryLong = // assume value here
NSLog(@"%f", veryLong); // of course wrong...
6 Answers
long long veryLong = // assume value here
NSLog(@"My long long is: %lld", veryLong); // now it's right

The String Format Specifiers section of the String Programming Guide for Cocoa is a great bookmark for your browser ... ;-)

Try using %lli.

I'd have written simply %lli, but SO doesn't like short answers.

Yet another way though unnecessary if it's a plain old type and not already an NSNumber, if you convert this to an NSNumber or something similar then the included format method will automatically do the right thing if you just use %@.

int64 / long long int "%lld" uint_32_t "%u"

Related