本文介绍了在iOS和OSX上使用unsigned int和unsigned long编译NSLog而不发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在iOS NSUInteger
是 unsigned int
,在OSX上它是 unsigned long
。如何制作类似
On iOS NSUInteger
is a unsigned int
, on OSX it is a unsigned long
. How can I make a print statement like
NSLog(@"Array has %d elements.",[array count]);
在没有警告的情况下在两个平台上编译?我当然可以使用 #ifdef #else #endif
构造,但这将添加4行代码。我也可以将返回值强制转换为unsigned int。有更短的解决方案吗?
compile on both platforms without a warning? I can of course use an #ifdef #else #endif
construct but that will add 4 lines of code. I could also cast the return value to unsigned int. Is there a shorter solution?
推荐答案
两个中较大者的演员怎么样?
How about a cast up to the larger of the two?
NSLog(@"Array has %ld elements.",(unsigned long)[array count]);
iOS中没有任何警告,我认为这是OSX中的无操作。
No warning in iOS, and I think it's a no-op in OSX.
这篇关于在iOS和OSX上使用unsigned int和unsigned long编译NSLog而不发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!