Using Environment Values to avoid unnecessary body re-evaluations and make our views more self-contained.
Dependency injection is a 25-dollar term for a 5-cent concept. -James Shore
Dependency Injection is a fancy way of saying that we will provide an object with the object(s) it requires or depends on, to perform its job.
In SwiftUI, a very common way of implementing Dependency Injection is by using environment objects. By injecting an object into our view hierarchy we can abstract the logic and data out of our views and into classes, allowing us to follow the single-responsibility principle, and making our code more testable.
For an example, let’s imagine that we have a
UserSettings class with a few properties.