NSU整数转换

大卫542

我有以下声明:

NSLog(@"The count of the book is now: %i", [book.book count]);

这给了我一个警告,那就是我使用了错误的格式参数。

  • 1)为什么我不能将计数打印为整数?(这不是最合理吗?)
  • 2)编写上述声明的正确方法是什么?
米克·麦卡勒姆(Mick MacCallum)

您可以但可能不应该将其打印为有符号整数,因为它可能包含会使有符号整数溢出的值。另外,根据平台是32位还是64位,NSUInteger可以定义为unsigned int或unsigned long,因此您可以通过将其强制转换为unsigned long,然后使用unsigned long格式说明符来进行处理。

NSLog(@"The count of the book is now: %lu", (unsigned long)[book.book count]);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章