When the environment object is instantiated, the static variable holding the implementation for the API is then set to the mock implementation. At which point any interaction with the View Model will interact with mock data.
When the environment object is instantiated, the static variable holding the implementation for the API is then set to the mock implementation. At which point any interaction with the View Model will interact with mock data.
This is a trick used to instantiate an object for the preview only, which allows me to fill the static variable from the previous step with the mock implementation.
This is a trick used to instantiate an object for the preview only, which allows me to fill the static variable from the previous step with the mock implementation.
Side note: I use a struct here to work around the limitation of using an extension.
Side note: I use a struct here to work around the limitation of using an extension.
This will allow me to initialize that variable differently based on whether I am in a preview or the actual app.
For the real implementation, I would usually set that variable at the App level or similar.
This will allow me to initialize that variable differently based on whether I am in a preview or the actual app.
For the real implementation, I would usually set that variable at the App level or similar.
This will enable me to consume the API while maintaining multiple implementations for it.
This will enable me to consume the API while maintaining multiple implementations for it.