title: SwiftUI: Storing an Array in UserDefaults
body: <p>i am desperate at a point that is probably very easy to solve.
  It is no problem for me to store a bool value in UserDefaults. see the attached code.
  But I can't manage to change it in a way that I can store multiple toggles with one array.</p>
  <p>Anybody got an idea?</p>
  <pre><code>import SwiftUI
  import Foundation
  
  struct ContentView: View {
      
      @ObservedObject var settings = settingsStore()
      
      var body: some View {
          VStack{
              
              Toggle (isOn: self.$settings.isFavorit) {
                  Text(&quot;&quot;)
                  }
          }
          .background(self.$settings.isFavorit.wrappedValue ? Color.green : Color.red)
      }
  }
  
  
  class settingsStore: ObservableObject{
      
      
      @Published var isFavorit: Bool = UserDefaults.standard.bool(forKey: &quot;isFavorit&quot;){
          didSet {
              UserDefaults.standard.setValue(self.isFavorit, forKey: &quot;isFavorit&quot;)
          }
      }
      
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          /*@START_MENU_TOKEN@*/Text(&quot;Hello, World!&quot;)/*@END_MENU_TOKEN@*/
      }
  }
  </code></pre>