Group Group Group Group Group Group Group Group Group

Chapter 15 multiple settings

In chapter 15, the HNReader app has a settings page with one setting (keywords), but how can you modify it so that your settings app could have multiple settings without having multiple env variables.

I was trying to use a dictionary to store all the settings, but I can’t find a way to assign that as an env variable.

Here are my settings as a dictionary:

import Foundation

    class Settings: ObservableObject {

    @Published var settingsDict : Dictionary<String, Any> = ["direction" : Directionality.right]
     // Some value may be enums, other strings, others numbers
   init() {}
}

When I try to subscribe to it:

   userSettings.settingsDict
        .mapValues{ $0 }
        .assign(to: \.settings, on: viewModel) // Value of type 'Dictionary<String, Any>' has no member 'assign'
        .store(in: &subscriptions)

Is there a way to send all settings at once?