Created
December 20, 2016 09:35
-
-
Save josephchang10/158747d8b79fdbcf67eb8debe66a1780 to your computer and use it in GitHub Desktop.
可选值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nickName: String? = nil | |
let fullName: String = "John Appleseed" | |
let informalGreeting = "Hi \(nickName ?? fullName)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
另一种处理可选值的方法是通过使用 ?? 操作符来提供一个默认值。如果可选值缺失的话,可以使用默认值来代替。