Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IOUs! from code: #95

Open
ibeckermayer opened this issue Apr 23, 2020 · 1 comment
Open

Remove IOUs! from code: #95

ibeckermayer opened this issue Apr 23, 2020 · 1 comment

Comments

@ibeckermayer
Copy link
Contributor

class BaseViewController: UIViewController {
var header: Header!

@ibeckermayer
Copy link
Contributor Author

@madhavajay I understand the motivation for this, but the issue is a bit more complex than it first seems. Our various reusable parts under UIComponents all take a parentVC: BaseViewController in their init function. This makes sense semantically, because each of these parts demands a parent ViewContoller in order to be drawn on the screen. It also turned out to be necessary in order to add MenuItems to the Menu that trigger a segue in its init function.

At first I thought I would just instantiate them with default values in each subclass of BaseViewController, but that doesn't work because they need to take a BaseViewController in their init, which means that the BaseViewController's init needs to be called first. So then I tried making a call to super.init() in each BaseViewController, but then the compiler started complaining to me that I needed to implement this init function as well, alongside my custom init:

required init?(coder: NSCoder) {
    super.init(coder: coder)
}

But when I implement that init function, the compiler starts complaining that "Property '' not initialized at super.init call". But again its not possible to initialize it before the super.init, because the UIComponent needs the BaseViewController instance passed to it in order to be initialized.

So the compromise I came up with was to make those all IOUs! that get initialized in viewDidLoad (or, in the case of BaseViewController, in viewDidLayoutSubviews, for an idiosyncratic iOS platform reason related to when the struct denoting the Safe Area gets filled in). The ! denotes that this object should indeed be there for all intents and purposes, its only an "optional" for this convoluted chain of reasons, but you should expect it to be there. The other option was to make it Optional? and use a ton of ?'s everywhere, but that was ugly both in code and violated the semantics of Optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant