简体   繁体   English

在ARC下使用IBOutlet属性的用处?

[英]Usefulness of using properties for IBOutlets under ARC?

Under ARC, what's the point of making every IBOutlet a property? 在ARC下,让每个IBOutlet成为财产的重点是什么? What would be the downside of using ivars for IBOutlets used only internally by the view controller? 对于仅在视图控制器内部使用的IBOutlet使用ivars会有什么缺点?

如果你没有使用setter / getter方法做任何事情,不要依赖于那些属性的键值观察,并且不要预期子类会从覆盖这些属性中受益,那么使用它并没有真正的缺点在ARC下的IBOutlets的ivars。

I've been using ivars for my "private" IBOutlets and ran into memory leak problems. 我一直在为我的“私人”IBOutlets使用ivars并遇到内存泄漏问题。 I think it's because my IBOutlets used the __unsafe_unretained attribute instead of __weak . 我认为这是因为我的IBOutlets使用__unsafe_unretained属性而不是__weak I can't use __weak because it's not supported on iOS 4 (I want my app to be backwards compatible with iOS 4). 我不能使用__weak因为iOS 4不支持它(我希望我的应用程序向后兼容iOS 4)。 It's difficult to grasp what's really happening with ARC, IBOutlets, viewDidUnload, and all that mess. 很难理解ARC,IBOutlets,viewDidUnload以及所有混乱中真正发生的事情。 Sigh... 叹...

Anyways, when I changed my IBOutlets from ivars to properties, the memory leak issues went away. 无论如何,当我将IBOutlets从ivars更改为属性时,内存泄漏问题就消失了。

So, to answer my own question, one downside of using ivars for IBOutlets is that you might run into memory leaks if you have the __unsafe_unretained attribute. 因此,回答我自己的问题,对于IBOutlets使用ivars的一个缺点是,如果你有__unsafe_unretained属性,你可能会遇到内存泄漏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM