Emile Cormier
Emile Cormier

Reputation: 29209

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?

Upvotes: 3

Views: 905

Answers (2)

Emile Cormier
Emile Cormier

Reputation: 29209

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.

Upvotes: 0

BJ Homer
BJ Homer

Reputation: 49034

If you don't use the setter/getter methods for anything, don't rely on key-value observing for those properties, and don't anticipate that a subclass would benefit from overriding those properties, then there's no real downside to just using ivars for IBOutlets under ARC.

Upvotes: 8

Related Questions