LoginSignup
33
35

More than 5 years have passed since last update.

XCodeでのwarning抑制方法

Posted at

コードを書いていてwarningを抑制したい時があると思います(deprecated warningなど)。clangでは一時的にwarningを制御する事ができます。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
  NSString *caption = @"hoge";
  captionHeight = [caption sizeWithFont:captionFont constrainedToSize:CGSizeMake(320, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping].height;
#pragma clang diagnostic pop

clang diagnostic pushclang diagnostic popで挟めばOKです。warningを一時的に無効にしているのは

#pragma clang diagnostic ignored "-Wdeprecated-declarations"

の部分です。-Wdeprecated-declarationsがdeprecated warningを無視するようにしています。よく使うのは

ignored parameter 内容
-Wunused-variable 未使用変数へのwarning
-Wdeprecated-declarations 廃止予定の関数呼び出しへのwarning

ぐらいでしょうか。ignored parameterの調べ方はXCodeのナビゲーションバーに表示されているWarning上でCtrl+Clickで'Reveal in Log'を選択すると

warning: unused variable 'a' [-Wunused-variable]

と出てくるので調べられます。

33
35
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
33
35