title: Appending an Array in NSUserDefaults Swift
body: <p>So I want to append an array in the NSUserDefaults, not save an entirely new one. The issue is that I want the array to be a logged history of a certain type of user interaction so I need to be appending an existing array in the NSUserDefaults, and not overwriting it. </p>
  
  <p>i.e Not: </p>
  
  <pre><code>var data = [String]()
  var questionsAsked = [String]()
  
  func storeData() {
  
      let defaults = NSUserDefaults.standardUserDefaults()
  
      defaults.setObject(questionsAsked, forKey: "questionsAsked")
      defaults.setObject(data, forKey: "data")
  
      var storedQuestionsAsked = defaults.objectForKey("questionsAsked") as? [String] ?? [String]()
  
      var storedData = defaults.objectForKey("data") as? [String] ?? [String]()
  
  }
  </code></pre>
  
  <p>The array(s) are based in my Modal, and the appending is occurring by appending that array in the ViewController of that Modal</p>
  
  <p>I tried just calling a function like this, but this is just calling an empty array because its never being re-saved to the NSUserDefaults:</p>
  
  <pre><code>func updateQuestionsAsked(questionAsked: String, answerGiven: String) {
  
      let defaults = NSUserDefaults.standardUserDefaults()
  
      defaults.setObject([String](), forKey: "questionsAsked")
      defaults.setObject([String](), forKey: "data")
  
      var storedQuestionsAsked = defaults.objectForKey("questionsAsked") as? [String] ?? [String]()
      var storedData = defaults.objectForKey("data") as? [String] ?? [String]()
  
      storedData.append(questionAsked)
      storedQuestionsAsked.append(answerGiven)
  
      NSUserDefaults.standardUserDefaults().synchronize()
  }
  </code></pre>
  
  <p>Is there some kind of synchronization thing I'm missing? I'm sure this is super simple but I'm just spacing out on what to do. Thanks!</p>