2016-08-05 118 views
0

这比任何事情都更令人讨厌。有没有其他人跑过这个?NSLogs中的unsigned int和unsigned long Xcode警告

出于调试目的,我正在吐出_fetchedResults的计数。当我使用%u时,Xcode给我一个unsigned int警告,然后提供将其更改为%lu

enter image description here

OK的Xcode,当然,请便。

然后立刻在我再次与unsigned long警告,树皮,并提供%lu将其更改为一个%u。循环重复。当然,我可以删除NSLog,但我在测试过程中使用它。坦率地说,它比其他任何东西都更令人讨厌。

enter image description here

其他人遇到过这个之前?不知道它有多重要,但我在Xcode 7.3上部署目标为9.0.x.

+1

有时用于调试目的,我使用'%@'和'@(myIntLongOrWhatverPrimitiveNum)'因为的XCode可以在64位/ 32位器件的情况下抛出警告。 – Larme

+0

我不会添加其他答案,因为他们解释了解决方案,但是,我真的会建议使用'%@'和'@(myInt)'。这是最简单的解决方案。 – Sulthan

回答

3

看看这个SO螺纹: Compile NSLog with unsigned int and unsigned long

它says-

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

而且还says-

最好的办法是NSLog(@"%lu", (unsigned long)array.count);为NSUInteger,
NSLog(@"%ld", (long)button.tag);为NSInteger的:32位或64位无警告。

+0

甜美感谢你DashAndRest和user3182143 ...我收到过最快的答案Stack。周末愉快。 :-) – Drew

2
NSLog(@"row: %lu", (unsigned long)[_fetchedResultsController.fetchedObjects count]); 

说明

在32位平台的32位无符号整数

64位在64位平台无符号整数。

Type  Format Specifier Cast 
----  ---------------- ---- 
NSInteger %ld    long 
NSUInteger %lu    unsigned long 
相关问题