Skip to content

Instantly share code, notes, and snippets.

@ratkins
Last active December 29, 2015 10:09
Show Gist options
  • Save ratkins/7655315 to your computer and use it in GitHub Desktop.
Save ratkins/7655315 to your computer and use it in GitHub Desktop.
A technique for injecting a UINavigationController created by UIStoryboard into a Typhoon-managed object

We had the need to expose a UINavigationController created by UIStoryboard to a class that was managed by Typhoon. We were already using a technique to inject a ViewController's properties with Typhoon-managed objects, but we wanted to go the other way around and get the UINavigationController that was created by UIStoryboard into the Typhoon universe.

Because the UIStoryboard (and therefore UINavigationController) doesn't actually exist when Typhoon is doing its thing, we had to create a NavigationControllerProxy that would look it up and return it when it was asked. This could then be injected by Typhoon into any object which neede the UINavigationController:

// NavigationControllerProxy.m

- (UINavigationController *)navigationController {
    return (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
}

I'm not 100% satisfied by this, it feels a bit "hacky" but it's working for us for the moment.

@jasperblues
Copy link

Looks good. . . . the normal "lazy" components didn't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment