Chapter 14
Data Sharing with Combine and Environment Objects

In the previous chapter, you learned how to lay out a form using the Form component. However, the form is not functional yet. No matter what options you select, the list view doesn't change to reflect the user's preference. This is what we're going to discuss and implement in this chapter. We will continue to develop the setting screen and make the app fully functional by updating the restaurant list in reference to the user's personal preference.

Specifically, there are a few topics we will discuss in later sections:

  1. How to use enum to better organize our code
  2. How to store the user's preference permanently using UserDefaults
  3. How to share data using Combine and @EnvironmentObject
Figure 4. The list view now refreshes its items when you change the filter preference
Figure 4. The list view now refreshes its items when you change the filter preference

To access the full content and the complete source code, please get your copy at https://www.appcoda.com/swiftui.

results matching ""

    No results matching ""