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
以上是内存溢出为你收集整理的objective-c – Xcode警告:Format指定类型’long’但参数的类型为’int _Nullable’全部内容,希望文章能够帮你解决objective-c – Xcode警告:Format指定类型’long’但参数的类型为’int _Nullable’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)