ios - 在 iOS 和 OSX 上使用 unsigned int 和 unsigned long 编译 NSLog 而没有警告

标签 ios xcode macos

在 iOS 上 NSUInteger 是一个 unsigned int,在 OSX 上它是一个 unsigned long。我怎样才能做出像

这样的打印语句
 NSLog(@"Array has %d elements.",[array count]);

在没有警告的情况下在两个平台上编译?我当然可以使用 #ifdef#else #endif 构造,但这会添加 4 行代码。我还可以将返回值转换为 unsigned int。有更短的解决方案吗?

最佳答案

将两者中较大的一个进行转换怎么样?

NSLog(@"Array has %ld elements.",(unsigned long)[array count]);

在 iOS 中没有警告,我认为它在 OSX 中是空操作。

关于ios - 在 iOS 和 OSX 上使用 unsigned int 和 unsigned long 编译 NSLog 而没有警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14349844/

相关文章:

ios - OSX 生成的 key 无法加密(SecKeyCreateRandomKey 和 SecKeyCreateEncryptedData)

ios - TableView:如何从 didSelectRowAtIndexPath 例程中选择另一行的值

iphone - 在 XCode 中编辑运行脚本构建阶段

python - 在 Mac OS X 中移动光标(在 Python 和/或 R 中)

cocoa - 添加 subview 以将 PDFView 作为 subview 进行查看

html - 内部导航被拒绝 : <allow-navigation not set> in Cordova on iOS

iphone - [__NSCFNumber 长度] : unrecognized selector sent to instance 0x6d21350

ios - 使用 ASIHTTPRequest 将 .caf 发送到服务器

xcode - 为什么编译器告诉 'Expression was too complex'

xcode - 我应该如何让 Xcode 链接使用 C++ 静态库的 iOS 项目