2
3

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】まとめてアンラップする

Posted at

はじめに

if letguardをまとめられるのを知らなかったので記録しておきます。

if let

let int: Int? = 10

let string: String? = "hello world"

if let int, let string {
    print(int)
    print(string)
}

ポイント

if let int = int, let string = string

if let int, let string

は同じ意味

guard

let int: Int? = 10

let string: String? = "hello world"

guard let int = int, let string = string else { return }

print(int)
print(string)

ポイント

guard let int = int, let string = string else { return }

guard let int, let string else { return }

は同じ意味

おわり

これを使うとコードがすっきりするので積極的に使っていきたいです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?