Skip to content

Instantly share code, notes, and snippets.

@josephzhang23
Created December 20, 2016 09:35
Show Gist options
  • Select an option

  • Save josephzhang23/158747d8b79fdbcf67eb8debe66a1780 to your computer and use it in GitHub Desktop.

Select an option

Save josephzhang23/158747d8b79fdbcf67eb8debe66a1780 to your computer and use it in GitHub Desktop.
可选值
let nickName: String? = nil
let fullName: String = "John Appleseed"
let informalGreeting = "Hi \(nickName ?? fullName)"
@josephzhang23
Copy link
Author

另一种处理可选值的方法是通过使用 ?? 操作符来提供一个默认值。如果可选值缺失的话,可以使用默认值来代替。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment