0
1

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 3 years have passed since last update.

Optiona型変数からguard letで値を取り出す

Last updated at Posted at 2020-04-10

Optional型変数から値を取り出す際、そこにnilが入っているとエラーの原因となることがあります。そこで、gurad letを使用することでnilを識別し値を安全に取り出すことができます。

gurad letの使い方

guard let sampleNonNil = sampleOptionl else {
    //sampleOptionlがnilである場合
    return
}
//その後の処理

sampleOptionlがnilでなければその後の処理が実行され、sampleOptionlがnilであればreturnされます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?