There are several posts on this subject, but I can't see the answer to this problem in them. The following lines produce the title error:
let pdf_url = NSURL.fileURL(withPath: inputfile)
let pdf_doc = PDFDocument.init?(url: pdf_url) as! URL
I understand that the init method can take a variety of data types, but surely I've made it pretty clear that I want a URL.
Error message is:
error: ambiguous reference to member 'init(url:)'
A problem which may be related is that Xcode occasionally tells me to use URL, not NSURL, in the first line, but then complains that URL doesn't have the fileURL method. (I also tried CGPDFDocument, but that wanted a CFURL, and wouldn't accept NSURL, even though they are supposed to be "toll-free bridged".)
The error occurs because you (try to) cast PDFDocument to URL.
You probably mean
PDFDocument.init?(url: pdf_url as! URL)
But the recommended Swift 3 syntax is
let pdfURL = URL(fileURLWithPath: inputfile) // returns a non-optional URL
let pdfDoc = PDFDocument(url: pdfURL)
Please use – Swift – camel case variable names rather than – javascript / php – snake case.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments