简体   繁体   中英

Usefulness of using properties for IBOutlets under ARC?

Under ARC, what's the point of making every IBOutlet a property? What would be the downside of using ivars for IBOutlets used only internally by the view controller?

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

I've been using ivars for my "private" IBOutlets and ran into memory leak problems. I think it's because my IBOutlets used the __unsafe_unretained attribute instead of __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). It's difficult to grasp what's really happening with ARC, IBOutlets, viewDidUnload, and all that mess. Sigh...

Anyways, when I changed my IBOutlets from ivars to properties, the memory leak issues went away.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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