首页 > 代码库 > [我的疑问]String? = "Skiy Chan" 中的问号是什么意思?

[我的疑问]String? = "Skiy Chan" 中的问号是什么意思?

1 var optionalName : String? = "Skiy Chan"

String? = "Skiy Chan" 中的问号是什么意思?
目前还在看api和视频教程,暂时还没弄懂这个意思。特别是api中的那串代码:

var optionalString : String? = "Hello"optionalString == nilvar optionalName : String? = "Skiy Chan"var greeting = "Hello!"if let name = optionalName {        greeting = "Hello, \(name)"    }println(greeting)

println出来的结果是:

Hello, Skiy Chan

 难道是这样表示的?:

optionalName ? nil : "Skiy Chan"


++++++++++++++++++++++++++
++++++++++++++++++++++++
通过cocoachina的一篇文章,我已经基本明白这意思了:

let hashValue = http://www.mamicode.com/strValue?.hashValue

strValue是Optional的字符串,如果strValue是nil,则hashValue也为nil,如果strValue不为nil,hashValue就是strValue字符串的哈希值

上述片段取于:http://joeyio.com/ios/2014/06/04/swift---/