I'm coding Objective C in Xcode 15 and found this NSLog %d problem. The code I used to test:
int someInt = -1;
NSLog(@"AppDelegate status: %d (%d) ((%.0f)) %@ -> %d)" ,
someInt,
-1,
someInt * 1.0,
[NSString stringWithFormat:@"%d", someInt],
[NSString stringWithFormat:@"%d", someInt].intValue);
The result in Log:
AppDelegate status: 18,446,744,073,709,551,615 (18,446,744,073,709,551,615) ((-1.0000)) -1 -> 18,446,744,073,709,551,615)
So for -1,
- it's printed as 8,446,744,073,709,551,615 with %d
- Converted to float using %f shows correct -1.0000
- Converted to NSString shows correct -1
But
- %d with -1 doesn't work
- %d with someInt doesn't work
- %d with NSString converted back to intValue doesn't work.
Seems like NSLog is printing %d as a unsigned int. In addition, using printf is fine with -1 and %d.
Is there some setting problem of my Xcode? Any ideas how to fix this?
From Xcode 15 Release Notes:
Apparently there's a bug in the new logging system. Workaround: Edit Scheme and add environment variable
IDELogRedirectionPolicywith valueoslogToStdio.