[BS-15] Values of type 'NSInteger' should not be used as format arguments


Values of type 'NSInteger' should not be used as format arguments

 

苹果app支持arm64以后会有一个问题:NSInteger变成64位了,和原来的int (%d)不匹配,使用[NSString stringWithFormat:@“%d", integerNum]; 会报如下警告:

Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead

 

解决办法:

1、系统推荐方法   [NSString stringWithFormat:@“%ld"(long)integerNum];

2、强制转换int    [NSString stringWithFormat:@"%d"(int)integerNum];

3、转为数字对象  [NSString stringWithFormat:@“%@", @(integerNum)];

4、使用%zd占位符  [NSString stringWithFormat:@“%zd"integerNum];  (最简单的方法)

补充:

关于%zd格式化字符,只能运行在支持C99标准的编译器中,表示对应的数字是一个size_t类型,size_t是unsigned int 的增强版,表示与机器类型相关的unsigned类型,即:size-t在32位系统下是unsigned int(4个字节),在64位系统中为long unsigned int(8个字节)。

 

C语言转义字符

     \\ 反斜杠

  \a 警告

  \b 退格

  \f 换页

  \n 换行

  \r 回车

  \t 跳格Tab

  \v 垂直跳格

      空格在输入时不需要转义,直接敲空格

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM