marcosgriselli/Sizes

Improve Sizes setup

marcosgriselli opened this issue · 6 comments

Making users set SizesViewController as their apps root view controller is not the best approach. There must be a better way to do this that also supports setup via Storyboards.

b-onc commented

I've added this snippet to the end of our AppDelegate.swift file:

#if DEBUG
class SizesWindow: UIWindow {
    override var rootViewController: UIViewController? {
        didSet {
            if let rootVC = rootViewController, !rootVC.isKind(of: SizesViewController.self) {
                let root = SizesViewController()
                rootViewController = root
                root.contain(viewController: rootVC)
            }
        }
    }
}
#endif

and I've set my window as:

#if DEBUG
window = SizesWindow(frame: UIScreen.main.bounds)
#endif

didn't need to set anything else up. I think it's better than setting up rootViewController, since we were setting it more than a single place, it needed changes in many places, whereas with this approach, a single setting fixes

Hey @b-onc, I really like this approach we can even so something with get for the rootViewController to return the contained view controller so people don't need to change any code if they're depending on something like UIApplication.shared.windows.first?.rootViewController as? XViewController.

Would you like to send a PR?

b-onc commented

@marcosgriselli I'll gladly open a PR, including get approach. Thanks!

@b-onc I have some free time today. Ping me if you want to work on this together.

b-onc commented

@marcosgriselli I'm working on it, you can expect a PR in 1 hours (Oct 14 16:30 UTC+2)

b-onc commented

@marcosgriselli PR opened.