[BS-15] Values of type 'NSInteger' should not be used as format arguments

Values of type 'NSInteger' should not be used as format arguments

 

蘋果app支持arm64之後會有一個問題:NSInteger變成64位了,和原來的int (%d)不匹配,使用[NSString stringWithFormat:@「%d", integerNum]; 會報以下警告:

Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' insteadapp

 

解決辦法:spa

一、系統推薦方法   [NSString stringWithFormat:@「%ld"(long)integerNum];orm

二、強制轉換int    [NSString stringWithFormat:@"%d"(int)integerNum];對象

三、轉爲數字對象  [NSString stringWithFormat:@「%@", @(integerNum)];ci

四、使用%zd佔位符  [NSString stringWithFormat:@「%zd"integerNum];  (最簡單的方法)編譯器

補充:string

關於%zd格式化字符,只能運行在支持C99標準的編譯器中,表示對應的數字是一個size_t類型,size_t是unsigned int 的加強版,表示與機器類型相關的unsigned類型,即:size-t在32位系統下是unsigned int(4個字節),在64位系統中爲long unsigned int(8個字節)。it

 

C語言轉義字符

     \\ 反斜槓編譯

  \a 警告ast

  \b 退格

  \f 換頁

  \n 換行

  \r 回車

  \t 跳格Tab

  \v 垂直跳格

      空格在輸入時不須要轉義,直接敲空格

相關文章
相關標籤/搜索