title: Data in my iOS app vanishes after a couple of days
body: <p>I have an iPhone app that stores data locally in an array. I was testing the app on my actual iPhone and it works fine except that the data vanishes after a couple of days. I am curious to see if this has happened to anyone else and if a solution was found. Here is a sample of the code that stores the data:</p>
  
  <pre><code>var doctorsArray = [Doctors]()
  
  func storeDoctorsArray() {
      doctorsArray.sort(by: {(a: Doctors, b: Doctors) -&gt; Bool in
          return a.firstName &lt; b.firstName
      })
  
      let defaults = UserDefaults.standard
      let data = NSKeyedArchiver.archivedData(withRootObject:     doctorsArray)
      defaults.set(data,forKey: "stored_doctors_data")
      defaults.synchronize()
  } 
  </code></pre>
  
  <p>And to get data:</p>
  
  <pre><code>func loadDoctorsArray() {
      if let storedArray = UserDefaults.standard.object(forKey: "stored_doctors_data") as? Data {
          doctorsArray = NSKeyedUnarchiver.unarchiveObject(with: storedArray) as! [Doctors]
  </code></pre>
  
  <p>Again as mentioned, the app works fine and the data stores and displays as expected but vanishes after a couple of days.</p>