Skip to content

Instantly share code, notes, and snippets.

@STAR-ZERO
Created June 10, 2016 03:32
Show Gist options
  • Save STAR-ZERO/edb6d8d6e7ec3c55b8ded8bd1b608090 to your computer and use it in GitHub Desktop.
Save STAR-ZERO/edb6d8d6e7ec3c55b8ded8bd1b608090 to your computer and use it in GitHub Desktop.
もっと良い書き方無いかな?
func foo() -> String? {
return nil
}
let hoge: String
if let t = foo() {
// nilじゃなければ、その値を使いたい
hoge = t
} else {
// nilだったらデフォルト設定したい
hoge = "default"
}
print(hoge)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment