title: Share pdf document .Swift
body: <p>I am trying to share a pdf document that I open in pdfView. But for some reason activityViewController is empty, and I can’t send a file somewhere.
  Please tell me how to fix my code!</p>
  
  <p>Code of my ViewController</p>
  
  <p><strong>pdfView.swift</strong></p>
  
  <pre><code>import UIKit
  import PDFKit
  
  var nameFile:String?
  var titleChapter:String?
  
  class pdfView: UIViewController {
  
      @IBOutlet weak var pdfDocView: PDFView!
  
      // Share doc
      @IBAction func shareDocAction(_ sender: UIBarButtonItem) {
  
          let path = Bundle.main.path(forResource: nameFile,  ofType:"pdf")
          let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path!))
  
          var filesToShare = [Any]()
          filesToShare.append(pdfDocument!)
  
          let activityViewController = UIActivityViewController(activityItems: filesToShare , applicationActivities: nil)
          activityViewController.popoverPresentationController?.sourceView = self.view
          present(activityViewController, animated: true, completion: nil)
      }
  
      //Pdf view
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.navigationItem.title = titleChapter
          navigationController?.navigationBar.barTintColor = .white
  
          //name Documents for view
          if let path = Bundle.main.path(forResource: nameFile,  ofType:"pdf") {
              if let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) {
                  pdfDocView.displayMode = .singlePageContinuous
                  pdfDocView.autoScales = true
                  pdfDocView.displayDirection = .vertical
                  pdfDocView.document = pdfDocument
                  pdfDocView.canZoomIn()
                  pdfDocView.canZoomOut()
  
              }
  
          }
  
  
      }
  
  }
  </code></pre>