swift语言-隐式解析可选

前端之家收集整理的这篇文章主要介绍了swift语言-隐式解析可选前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

隐式解析可选

隐式解析可选和可选类型的区别

声明的时候需要在变量类型后面加叹号(!)。

@H_301_7@#import Foundation var optValue: Int! = nil if optValue != nil{ println("not nil") }else{ println("nil") }

强制解析时候可以不加叹号。

@H_301_7@#import Foundation var optValue: Int! = nil println(optValue)

猜你在找的Swift相关文章