NSInteger precedence = [self operatorPrecedence]; [d appendFormat:@"precedence:%d,",precedence];
得到:
Warning: Format specifies type ‘int’ but the argument has type
‘NSInteger’ (aka ‘long’)
而Xcode建议将%d更改为%ld.
但是,它只适用于32位或64位目标,因为NSInteger是:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64 typedef long NSInteger; typedef unsigned long NSUInteger; #else typedef int NSInteger; typedef unsigned int NSUInteger; #endif
对于32位和64位目标,杀死警告的最佳方式是什么?
解决方法
关注
the instructions in Apple’s 64-Bit Transition Guide.
对于NSInteger,使用%ld并将值转换为long.
[d appendFormat:@"precedence:%ld,(long)precedence];