title: NSKeyedArchiver does not archive my Codable class
body: <p>Here is my Codable class:</p>
  
  <pre><code>class SensorOutput: Codable {
  
      var timeStamp: Date?
  
      var gyroX: Double?
      var gyroY: Double?
      var gyroZ: Double?
  
      var accX: Double?
      var accY: Double?
      var accZ: Double?
  
      var magX: Double?
      var magY: Double?
      var magZ: Double?
  
      init() {}
  }
  </code></pre>
  
  <p>Here I try to write and read the object of that class to file:</p>
  
  <pre><code>    let myData = SensorOutput()
      myData.timeStamp = Date()
      myData.gyroX = 0.0
      myData.gyroY = 0.0
      myData.gyroZ = 0.0
      myData.accX = 0.0
      myData.accY = 0.0
      myData.accZ = 0.0
      myData.magX = 0.0
      myData.magY = 0.0
      myData.magZ = 0.0
  
      NSKeyedArchiver.archiveRootObject(myData, toFile: filePath)
  
      if let Data = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? SensorOutput {
          print (Data)
      }
  </code></pre>
  
  <p>This gives an error during the process of archiving:
  <a href="https://i.stack.imgur.com/3PnwI.png" rel="noreferrer">Error screenshot</a>
  <br></p>
  
  <p>PS: filePath I receiving in such way:</p>
  
  <pre><code>var filePath: String {
      //1 - manager lets you examine contents of a files and folders in your app; creates a directory to where we are saving it
      let manager = FileManager.default
      //2 - this returns an array of urls from our documentDirectory and we take the first path
      let url = manager.urls(for: .documentDirectory, in: .userDomainMask).first
      print("this is the url path in the documentDirectory \(String(describing: url))")
      //3 - creates a new path component and creates a new file called "Data" which is where we will store our Data array.
      return (url!.appendingPathComponent("Data").path)
  }
  </code></pre>
  
  <p>Reading/writing works with Int or Double and with other supported types, but not with my type. What’s wrong?</p>