LoginSignup
26
27

More than 5 years have passed since last update.

if let whereを忘れるのでメモ

Last updated at Posted at 2016-07-06

2019/09/25 追記

コメントにて、Swift4では if let where は使えなくなったとの情報を頂いたので
記事作成時の環境&バージョンを追記しておきます。

【確認環境】
Xcode 7.3.1
Swift 2.2

追記ココマデ

どうもコード書いてる途中で、モニョモニョってなる構文を見て確か少し綺麗にかける方法があるはず。
ってググっちゃうので戒めのアウトプット。

このif文が2回続くやつは

// audioPlayerがnilじゃないなら
if let player = audioPlayer {

    // 再生中なら
    if (player.playing) {
        player.stop()   // 停止
    }
}

これでいける

// audioPlayerがnilでなければ、
// where以降でbindingしたplayerを利用できる。
if let player = audioPlayer where player.playing {

    player.stop()   // 停止
}
26
27
2

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
26
27