2.UINavigationController stores view controllers in
NSArray
That is not a given.
@property(nonatomic,copy) NSArray *viewControllers;
That in no way indicates that there is an ivar called _viewControllers
or anything like it. It just tells us that there is some method -viewControllers
that will return us an NSArray
, and that there is some method setViewControllers:
that will accept one, and hints that it will make a copy of it (or at least behave like it made a copy of it). That is all it tells us. If you expand an NSNavigationController
in the debugger, you'll notice that there is no _viewControllers
ivar listed there.
If you poke around a little, you'll find that -viewControllers
is not implemented as a synthesized property. It just forwards onto -childViewControllers
(which is a UIViewController
property). OK, so doesn't that just move the problem? I mean -childViewControllers
is implemented as [NSArray arrayWithArray:_childViewControllers]
. Fair enough. You caught me.
But the same logic applies to [UIViewController navigationController]
. This declaration:
@property(nonatomic,readonly,retain) UINavigationController *navigationController
does not mean that it actually has a strong link. It just means that if you called setNavigationController:
, you would expect it to retain it. But you can't call setNavigationController:
. There is no such method (not even a private one). So all this is really promising is that there is a method called -navigationController
. And it's implemented as a call to +[UINavigationController _ancestorViewControllerOfClass:allowModalParent:]
. That just passes on to the UIViewController
implementation, which walks up the parentViewController
chain looking for a UINavigationController
. So there's no retain loop; it's dynamically determined.
But your question is still a good one. The header file here is confusing IMO, and I would open a radar against it. navigationController
should be listed as assign
or it should say nothing (even if that defaulted to strong
it would at least not be misleading).
BTW, if this stuff interests you, you really should drop $90 for Hopper. It's very good at this kind of exploration.