0
0

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.

BOOL を NSLog するときの Format はないらしく3項演算子を使うとすっきり書ける

Posted at

NSLog で BOOL 値を表示したいときフォーマットに書けるならいいんですができません。
そこで自分で YES or NO を出力してあげる必要があります。
何も考えずに書くとこうなりますが、

if (boolValue) {
  NSLog(@"YES");
} else {
  NSLog(@"NO");
}

複数行書くくらいなら

NSLog(@"%@", boolValue ? @"YES" : @"NO");

のほうがすっきりするよね!
独自で作ってもいいかも、

// 定義
MKLog(BOOL boolValue) {
  NSLog(@"%@", boolValue ? @"YES" : @"NO");
};

// 使用
MKLog(boolValue);
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?