Data argument not used by format string[Objective-C]

久しぶりにObjective-Cを触りNSLogでログに出しましたがログにでなく、warningがでてました。

Data argument not used by format string

NSDate *date = [NSDate date];

NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitWeekday fromDate:date];

NSInteger weekday = [components weekday];

NSLog(@"曜日-",weekday);

 

これをこうするとよい

 

NSLog(@"曜日-%ld",(long)weekday);

[Data argument not used by format string]

フォーマットされた文字列を使っていない引数のデータです

NSLog等で文字列を表示させたい場合に、必ず表示する文字列のデータをフォーマットする必要がありますが、そのフォーマット識別子を忘れてしまった時に出る警告。

 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA