LoginSignup
1
2

More than 5 years have passed since last update.

Swift .isEmptyを使うと・・・。

Last updated at Posted at 2019-01-05

インターンで教えて頂いたこと。
確かに.isEmptyを使った方がぱっと見わかりやすいし、見やすい。
わざわざ「空でない時」と否定を最初に持ってくるよりも「空の時」という風に肯定を最初に持ってくる方法が思いつかず、このようにしたのですが、その方法を教えてもらった時、うわー「.isEmpty」があったー!ってなりました。悔しい。

自分が書いたコード

if a != "" && b != "" && c != "" {
    "\(a),\(b),\(c)"
} else {
  return ""
}

下のほうがわかりやすい

if a.isEmpty && b.isEmpty && c.isEmpty {
    return ""
}
return "\(a),\(b),\(c)"

インターン先で「リーダルコード ~より良いコードを書くためのシンプルで実践的なテクニック~」という本を貸していただきました。数ページでもう面白い。
頑張っていきます!!!でもとりあえず期末テストの勉強!!!

1
2
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
1
2