lundi 27 février 2017

Correct Way to Use Dependency Injection - iOS

I have an object created in app delegate that I want to inject (dependency injection) into a specific class. My project setup is TableViewController -> when you select a cell it creates PlayerViewController. The project starts up on TableViewController so window?.rootViewController? is equal to that.

How would I pass the object created in app delegate directly to PlayerViewController on app launch? I believe this is not possible since at app launch PlayerViewController has not been created; so my solution is to pass the object first to TableViewController and then when you select a cell and create PlayerViewController, you pass the object again to it.

Is this the correct approach here?

Note:

  • I am using Storyboards (so I pass data around with segues).
  • I would like to avoid singletons if possible (unless it is the best approach here).

Aucun commentaire:

Enregistrer un commentaire