Should IBOutlet be weak or strong var? [duplicate]

不想你离开。 提交于 2019-12-03 10:46:00

问题


I'm using Xcode 6.2 for iOS projects. In older versions of Xcode, when a connection was create for an IBOutlet, it was always weak storage. Now when I create connections, they are defaulted to strong. I leave it that way and don't notice any difference.

Which version of Xcode did the default change to strong and why?


回答1:


Yes, previously outlets should generally be weak but Apple has changed that. Now they recommend to use strong outlets in the WWDC 2015 session Implementing UI Designs in Interface Builder. The only reason why it might be weak is retain cycle.




回答2:


It doesn't matter weak or strong the outlet is in most cases. You just be sure that you don't have strong reference cycles.

Subviews shouldn't have strong outlets to their superviews and view shouldn't have strong outlet to its controller, because superview already has strong reference to its subviews and controller has strong reference to its view.



来源:https://stackoverflow.com/questions/29421614/should-iboutlet-be-weak-or-strong-var

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!