在iOS和OSX上编译带有unsigned int和unsigned long的NSLog,不发出警告



在iOS上NSUIntegerunsigned 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中是一个No -op

如果将其转换为较大的一个呢?

NSLog(@"Array has %ld elements.",(unsigned long)[array count]);
No warning in iOS, and I think it's a no-op in OSX.

最新更新