2016-08-05 61 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 
相關問題