0

I have a nib in my ARC-enabled project which contains two UIViews at the top level. One is the main view and connected to a property view in the nib's owner, as usual, as a weak reference.

The second top level UIView is connected to another property in the file's owner. If I define that property also as weak, the system seems to be deallocating it immediately -- so it seems the nib loader only retains the first and main UIView in the nib file. Is this correct, and if so, is there any documentation to back this up? I've been looking for confirmation, but can't find it mentioned anywhere in Apple docs or on Stack Overflow.

I'm running Xcode 4.5.2.

occulus
  • 16,959
  • 6
  • 53
  • 76

1 Answers1

3

I don't think the nib loading mechanism does anything special with any of the objects. It obeys the property specification for whatever connections are defined. For example, the view property of UIViewController says:

@property(nonatomic, retain) UIView *view

There is nib documentation that says, "Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong." I believe this is now consistent for both OS X and iOS.

As I read it, that means you're responsible for creating a strong property referencing any top-level object that isn't already handled by the framework.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • Thanks Phillip, good info! Just didn't think about the view property in UIViewController being retained. – occulus Nov 13 '12 at 16:48
  • And of course all non-top-level items are retained by nature of being held by their parent components, and hence can be weak. – occulus Nov 13 '12 at 16:49