4

I've been reading Robert Martin's Clean Code book where it suggests we should separate a programs startup/construction process from its run time logic.

In Java (the language the book uses) this involves moving all aspects of construction to main and designing the rest of the system assuming all objects have been constructed and wired up appropriately with no knowledge of main.

How can I apply this to iOS development?

My immediate thought is to construct all my business logic and models within the AppDelegate didFinishLaunchingWithOptions function. Although I'm not sure if this is the right function to use and whether it's feasible or wise to attempt to setup the ViewControllers my app will use all in one place.

2 Answers2

1

Take a look at this iOS lifecycle. I have never read Clean Code, but I would suggest sticking to an MVC /MVVM pattern for iOS. iOS should do most of the heavy startup/construction process that I believe Robert is referring to.

Your business logic will go into your respective controllers (note I did not read that link I just grabbed the first google hit)

and MVVM... Full disclosure I am a little outdated on native iOS best practices I have since migrated to frameworks ... Ionic / React Native / etc...

Justin
  • 111
1

It doesn't work like that. Most of the work is done directly or indirectly in your view controllers. You don't create view controllers when the app is launched, but when they are needed. And the real work is done in viewDidLoad. And viewControllers get destroyed when not needed anymore.

Lots of work is done in Singletons, and they are created when they are needed. Sometimes there are Singletons whose existence is needed, you create them in appDidFinishLaunching. Singletons stay alive forever.

You don't assume all objects have been created. You can't assume that because many objects will never be created. You create objects when you need them.

gnasher729
  • 49,096