Swift seems to have changed again and I'm having trouble making this code work:
let pdf_url = URL(fileURLWithPath: filename)
let pdf_doc = PDFDocument.init(url: pdf_url)
let value = "Bibbly"
let diction = [kCGPDFContextCreator : value ] as Any
pdf_doc!.write(toFile: filename, withOptions: (diction as [PDFDocumentWriteOption : Any]))
I get the following error: 'CFString' is not convertible to 'Any'.
Anyone know what the problem is? The API reference is here:
https://developer.apple.com/documentation/pdfkit/pdfdocument/1436053-write
As in the API reference, the type of
withOptionsparameter is[PDFDocumentWriteOption : Any], so declaring yourdictionasAnyis not a good idea.With this line of code, Xcode has given me a suggestion:
So, I have Fix-ed it by accepting the suggestion:
This code compiles without problems.