Michael Long
May 5, 2022

--

EnvironmentObject, StateObject, and the like go a long way towards solving many of the issues for which DI is used. And those SwiftUI tools should be used to solve those problems.

That said, I think are still use cases for DI tools in SwiftUI in order to manage the dependencies required for items that are not directly in the View chain. Say a View has a ViewModel. How does the ViewModel get the dependencies and services that it needs?

I’m still writing the documentation, but you might look at Injectable, a lighter-weight DI system I think is better suited to those needs.
https://github.com/hmlongco/Injectable

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)