Skip to content

Instantly share code, notes, and snippets.

@josephchang10
Created December 20, 2016 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephchang10/158747d8b79fdbcf67eb8debe66a1780 to your computer and use it in GitHub Desktop.
Save josephchang10/158747d8b79fdbcf67eb8debe66a1780 to your computer and use it in GitHub Desktop.
可选值
let nickName: String? = nil
let fullName: String = "John Appleseed"
let informalGreeting = "Hi \(nickName ?? fullName)"
@josephchang10
Copy link
Author

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

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