swift中的options

来源:互联网 发布:中文域名证书生成器 编辑:程序博客网 时间:2024/06/05 14:41

You use optionals in situations where a value may be absent. An optional represents two possibilities: Either there is a value, and you can unwrap the optional to access that value, or there isn’t a value at all.
在值可能不存在的情况下, 您可以使用可选项。可选代表两种可能性:要么有是一个值,你可以解开可选访问的价值,或者有没有价值可言。
这里写图片描述
如上所示,由于可能会转化失败,在这种情况下就会返回nil。即有可能有值也可能没有值。如果为nil的情况下你用!号强制解包就会崩溃。

0 0
原创粉丝点击