title: Swift - Encode and Decode a dictionary [String:Any] into plist
body: <p>I am trying to store the dictionary in my class Marker but it is throwing an error saying it is not encodable or decodable. I can see the error is caused by the [String: Any] but how can I go around it?</p>
  
  <pre><code>var buttonActions : [String: [String: [String:Any]]] = [:]
  </code></pre>
  
  <p>Save and Load</p>
  
  <pre><code>func saveData() {
      let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("\(fileName).plist")
  
      let encoder = PropertyListEncoder()
      do {
          let data = try encoder.encode(markerArray)
          try data.write(to: dataFilePath!)
          print("Saved")
      } catch {
          print("Error Encoding \(error)")
      }
  }
  
  func loadData() {
      let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("\(fileName).plist")
  
      if let data = try? Data(contentsOf: dataFilePath!){
          let decoder = PropertyListDecoder()
          do {
              markerArray = try decoder.decode([Marker].self, from: data)
          } catch {
              print("Decode Error \(error)")
          }
      }
  </code></pre>
  
  <p>Class</p>
  
  <pre><code>class Marker : Encodable, Decodable {
      var UUIDpic: UUID = UUID()
      var alpha: Int = 1
      var buttonType: Int = 0
      var buttonActions : [String: [String: [String:Any]]] = [:]
      var buttonNameColor: String = ""
      var buttonNameFontSize: Int = 10
      var buttonShape: String = ""
      var loggerRect: String = ""
      var maskColor: String = ""
      var name: String = ""
  }
  </code></pre>