LoginSignup
38
34

More than 5 years have passed since last update.

Swift 2のguardはif letのようにOptional bindingを複数書いたり、whereを書いたりできる

Last updated at Posted at 2015-10-12

タイトルの通りなのですが、Swift 2のguardではif letのようにOptional bindingを複数書いたりできます。

guard let text = self.ageTextField.text, age = Int(text) else {
    return
}

また、if letのようにwhereで条件を指定することもできます。

guard let name = self.nameTextField.text where !name.isEmpty else {
    return
}

この書き方ができることを知っていれば、コードをよりスッキリ書くことができそうです。

38
34
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
38
34