title: Could not cast value of type 'NSKnownKeysDictionary1' () to '' ()
body: <p>I'm attempting to convert my <em>NSManagedObject</em> into a <em>Dictionary</em> so I can use serialize it for <em>JSON</em>.</p>
  
  <pre><code>func fetchRecord() -&gt; [Record] {
  
          let fetchRequest = NSFetchRequest&lt;Record&gt;(entityName:"Record")
          let context = PersistenceService.context
  
          fetchRequest.resultType = .dictionaryResultType
  
          do {
              records = try context.fetch(Record.fetchRequest())
  
          } catch {
              print("Error fetching data from CoreData")
          }
          print(records)
          return records
   }
  </code></pre>
  
  <p>I have loked at this question: <a href="https://stackoverflow.com/questions/29667202/how-to-convert-nsmanagedobject-to-nsdictionary">How to convert NSManagedObject to NSDictionary</a> but their method appears very different to mine. I have also attempted the methods provided in this question: <a href="https://stackoverflow.com/questions/46237755/coredata-object-to-json-in-swift-3/46268149#46268149">CoreData object to JSON in Swift 3</a>. However I am receiving this error </p>
  
  <blockquote>
    <p>Could not cast value of type 'NSKnownKeysDictionary1' (0x108fbcaf8) to 'iOSTest01.Record' (0x1081cd690)$ </p>
  </blockquote>
  
  <p>and I can't seem to find the solution. </p>
  
  <p>The error has been mentioned before here: <a href="https://stackoverflow.com/questions/32048458/core-data-could-not-cast-value-of-type-mytype-mytype-2-to-mytype">Core Data: Could not cast value of type &#39;MyType_MyType_2&#39; to MyType</a> but none of the methods are resolving my issue. Could anyone provide me a <em>Swift</em> solution for this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>To help the comment below I have added the following:</p>
  
  <pre><code>var record: Record!
  var records = [Record]()
  </code></pre>
  
  <p>Record+CoreDataClass: </p>
  
  <pre><code>public class Record: NSManagedObject {
  
  }
  </code></pre>
  
  <p>Record+CoreDataProperties:</p>
  
  <pre><code>extension Record {
  
      @nonobjc public class func fetchRequest() -&gt; NSFetchRequest&lt;Record&gt; {
          return NSFetchRequest&lt;Record&gt;(entityName: "Record")
      }
  
      @NSManaged public var name: String?
  
  }
  </code></pre>
  
  <p>This is where <code>records</code> are defined.</p>