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);
このような仕組みを利用して、デバッグ時とリリース時の切り替えをすると良さそうです。