NSLog(@"selected segment: %li",_segmentControl.selectedSegmentIndex);
selectedSegmentIndex属性的类型为NSInteger.
如果我将格式更改为%i,则会收到以下警告:
Format specifies type 'int' but the argument has type 'long _Nullable'
Nullable类型是否有任何新的格式说明符,或者这只是Xcode 7中的一个错误?
解决方法
NSLog(@"selected segment: %li",(long)_segmentControl.selectedSegmentIndex);
因为NSInteger在32位和64位架构中具有不同的长度.以前您没有看到警告,因为可能您只是针对64位架构进行编译.
我还建议阅读Apple Article,因为Xcode 7中有新的说明符(其中包括nullable和nonnull).
要回答您对评论的疑虑,请参阅此Apple document,其中说明了以下内容:
Type Specifiers
Script action: Warns about potential problems; may generate false negatives.
Typically,in 32-bit code you use the %d specifier to format int
values in functions such as printf,NSAssert,and NSLog,and in
methods such as stringWithFormat:. But with NSInteger,which on 64-bit
architectures is the same size as long,you need to use the %ld
specifier. Unless you are building 32-bit like 64-bit,these
specifiers generates compiler warnings in 32-bit mode. To avoid this
problem,you can cast the values to long or unsigned long,as
appropriate. For example:06001