标签:style class blog code http color
1 var optionalName : String? = "Skiy Chan"
String? = "Skiy Chan" 中的问号是什么意思?
目前还在看api和视频教程,暂时还没弄懂这个意思。特别是api中的那串代码:
var optionalString : String? = "Hello" optionalString == nil var 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 = strValue?.hashValue
strValue是Optional的字符串,如果strValue是nil,则hashValue也为nil,如果strValue不为nil,hashValue就是strValue字符串的哈希值
上述片段取于:http://joeyio.com/ios/2014/06/04/swift---/
[我的疑问]String? = "Skiy Chan" 中的问号是什么意思?,布布扣,bubuko.com
[我的疑问]String? = "Skiy Chan" 中的问号是什么意思?
标签:style class blog code http color
原文地址:http://www.cnblogs.com/skiy/p/3804513.html