Sunday, December 5, 2021

A detailed analysis of issues using SwiftUI’s EnvironmentObject keyword.

A detailed analysis of issues using SwiftUI’s EnvironmentObject keyword.


Thanks to Riccardo Cipolleschi for his explanation of the two common, if faulty, methods to deal with dependencies.


Comments: I understand Riccardo Cipolleschi points, but will have to spend time working with EnvironmentObject to decide. I like SwiftUI simplicity of using keywords.  That said, I am leaning towards Type Erasers. While I do not have a solution for better testing with SwiftUI, I dislike his solution of “explicitly defining the dependencies and to pass them in the View initializers”. For more than one or two dependencies, this becomes messy very quickly.


https://betterprogramming.pub/why-you-shouldnt-use-environmentobject-in-swiftui-a527d5c2bd


Liskov Subsitution Principle (mentioned in the article): https://en.wikipedia.org/wiki/Liskov_substitution_principle

No comments:

Post a Comment