title: Save PDFDocument to CoreData as NSData (how to convert it to NSData?)
body: <p>so this might be a trivial question, but I can't get it to work.
  I want to save a <code>pdf file</code> to CoreData after I dropped it onto a view (using IOS' <code>Drag&amp;Drop</code> feature)</p>
  
  <pre><code>func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
          session.loadObjects(ofClass: ComicBookPDFDocument.self) { (pdfItems) in
              let items = pdfItems as! [ComicBookPDFDocument]
  
              // "Cannot assign value of type 'ComicBookPDFDocument' to type 'NSData?'"
              self.file.data = items[0]
          }
  }
  </code></pre>
  
  <p><code>ComicBookPDFDocument</code> just subclasses <code>PDFDocument</code> to make it conforming to <code>NSItemProviderReading</code>:</p>
  
  <pre><code>final class ComicBookPDFDocument: PDFDocument, NSItemProviderReading {
  
      public static var readableTypeIdentifiersForItemProvider: [String] {
          return [kUTTypePDF as String]
      }
  
      public static func object(withItemProviderData data: Data, typeIdentifier: String) throws -&gt; ComicBookPDFDocument {
          return ComicBookPDFDocument(data: data)!
      }
  }
  </code></pre>
  
  <p>However, I get this compiler error from XCode:</p>
  
  <blockquote>
    <p>Cannot assign value of type 'ComicBookPDFDocument' to type 'NSData?'</p>
  </blockquote>
  
  <p>How can I save the pdf data from a <code>PDFDocument</code>? I couldn't find anything on the internet or the documentation.</p>
  
  <p>Thanks for any help</p>