title: Swift 3: PDFDocument crashes
body: <p>I'm trying to write a simple function that will get the number of pages in a PDF. Every code example I've seen now seems to fail with Swift 3, and whatever Xcode recommends still doesn't work.</p>
  
  <pre><code>func pageCount(filepath: String) -&gt; Int {
  
      let localUrl  = filepath as CFString
      let pdfDocumentRef = CFURLCreateWithFileSystemPath(nil, localUrl, CFURLPathStyle.cfurlposixPathStyle, false)
      let page_count = (pdfDocumentRef as! CGPDFDocument).numberOfPages
  
      return page_count
  }
  </code></pre>
  
  <p>And this doesn't work either:</p>
  
  <pre><code>func pageCount(filepath: String) -&gt; Int {
  
      let url = NSURL(fileURLWithPath: filepath)
      let pdf = CGPDFDocument(url)
      let page_count = pdf?.numberOfPages
  
      return page_count!
  }
  </code></pre>
  
  <p>Any ideas why?</p>