美文网首页
swift学习笔记

swift学习笔记

作者: halo_C | 来源:发表于2017-05-12 17:31 被阅读12次

可选类型使用注意事项:如果对象可能为nil, 应该使用?, 不要使用隐式解析可选类型(!),否则会出现运行期错误,导致crash。

“Use a weak reference whenever it is valid for that reference to become nil at some point during its lifetime. Conversely, use an unowned reference when you know that the reference will never be nil once it has been set during initialization.”

翻译:在引用对象的生命周期内,如果它可能为nil,那么就用weak引用。反之,当你知道引用对象在初始化后永远都不会为nil就用unowned.

相关文章

网友评论

      本文标题:swift学习笔记

      本文链接:https://www.haomeiwen.com/subject/mdftxxtx.html