10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Objective-cのデバッグログ出力

Last updated at Posted at 2014-08-20

NSLogのリリース時消し忘れ対策にマクロ関数を作ろう。

Xcodeのテンプレートでは、
デバッグ時にDEDUGというマクロ定数が定義されているので、
デバッグ時にのみNSLogを実行する様なマクロを作成する。
「Product」メニュー-「Archive」からリリース版を作成する際にはDEBUGは定義されていないので、ログは出力されません。

定数定義ファイル等に以下を記述

#if DEBUG
#define MyLog(fmt,...) NSLog((fmt),(__VA_ARGS__))
#else
#define MyLog(fmt,...)
#endif

ログ出力したいところで、以下のように利用する。

int hoge = 1;
MyLog(@"hoge = %d", hoge);

このような仕組みを利用して、デバッグ時とリリース時の切り替えをすると良さそうです。

10
10
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
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?