可選類型使用注意事項:如果對象可能為nil, 應該使用寂纪?枣宫, 不要使用隱式解析可選類型(!)褪猛,否則會出現(xiàn)運行期錯誤网杆,導致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.”
翻譯:在引用對象的生命周期內(nèi)伊滋,如果它可能為nil碳却,那么就用weak引用。反之笑旺,當你知道引用對象在初始化后永遠都不會為nil就用unowned.