title: Saving an array of dictionary coming from plist , with UserDefaults
body: <p>I need to save my array with UserDefaults because I want users have ability to add or delete rows them selves. I have a plist contains rows of dictionaries. I fill an array name countries with the rows on plist like this</p>
  
  <pre><code>var imageList = ["usaflag","gerflag","franceflag","jpflag","gerflag"]
  var countries = [Country]()
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let urlPlist = Bundle.main.url(forResource: "ListinFirstPage", withExtension: "plist")!
      let data = try! Data(contentsOf: urlPlist)
       do
      {
          countries = try PropertyListDecoder().decode([Country].self, from: data)
      }
      catch
      {
          // Handle error
          print(error)
      }
  
     savePlaces()
  
  
    }
  </code></pre>
  
  <p>Now the Array countries contains my plist rows . (filled with data of rows and works fine). my problem is how to save this array in UserDefaults , as it is an array of dictionaries seems it is a little complicated. I did this like the codes in bottom but it throws a thread in app delegate. </p>
  
  <p>I added this line in viewdidload to call save function </p>
  
  <pre><code>savePlaces()
  </code></pre>
  
  <p>and then here is my savePlaces function </p>
  
  <pre><code> func savePlaces(){
  
      do
      {
          let placesData = try NSKeyedArchiver.archivedData(withRootObject: countries, requiringSecureCoding: false)
      UserDefaults.standard.set(placesData, forKey: "places")
      print("Here is save function")
      }
      catch
      {
      print("SaveError")
      }
  
  
  }
  </code></pre>
  
  <p>It seems that problem is because of  <code>countries</code> array which it is an array of dictionaries coming from plist, because when I change this line </p>
  
  <pre><code>let placesData = try NSKeyedArchiver.archivedData(withRootObject: countries, requiringSecureCoding: false)
  </code></pre>
  
  <p>to this </p>
  
  <pre><code>let placesData = try NSKeyedArchiver.archivedData(withRootObject: imageList, requiringSecureCoding: false)
  </code></pre>
  
  <p>I mean I changed the countries to the imageList which is an array of strings , it works fine. I defined image list in first line </p>
  
  <pre><code> var imageList = ["usaflag","gerflag","franceflag","jpflag","gerflag"]
  </code></pre>
  
  <p>so the problem is <code>countries</code> but I do not know why and I will really appreciate for any ideas </p>