LoginSignup
0
0

More than 5 years have passed since last update.

warningの善処例

Last updated at Posted at 2017-02-11

はじめに

Xcode 8.2で型の不整合を警告されました(8.2固有の話ではありませんが)。いずれも書式側の型の見直しで解決しました。

Format specifies type 'long' but the argument has type 'int _Nullable'

原因

書式がlong型を明示していますが、この引数はint _Nullable型なので、不整合になっています。その警告が出ています。

善処例

before
[NSString stringWithFormat:@"Error code %ld", [transaction.error code]
after
[NSString stringWithFormat:@"Error code %zd", [transaction.error code]

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

原因

'NSInteger'型の値は書式引数として使われるべきではないことが指摘されています。Xcodeがヒントとして、long型への明示的なキャストを加えるように示しています。
そもそも、long型の値にして表示する必要がなければ、むしろ書式自体を修正すべきですね。

善処例

before
[NSString stringWithFormat:@"Error code %ld", error.code]
after_xcode
[NSString stringWithFormat:@"Error code %ld", (long)error.code]
after
[NSString stringWithFormat:@"Error code %zd", error.code]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0