14
4

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 1 year has passed since last update.

【Swift】for文内のif文を省略できるらしい

Posted at

はじめに

SwiftLintを使ってたら警告が表示されて気づいたのですが、for文内のif文はwhereを使って1文にできるらしいです。

やりかた

for user in users {
    if user == "SNQ-2001" {
        print("自分です")
    }
}
for user in users where user == "SNQ-2001" {
    print("自分です")
}

おわり

こういうコードの省略形みたいなの知るとめっちゃ嬉しくなっちゃいます笑

14
4
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
14
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?