swift学习笔记

可选类型使用注意事项:如果对象可能为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学习笔记)