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的情况下你用!号强制解包就会崩溃。
swift中的options
最新推荐文章于 2024-07-23 16:48:17 发布