import PDFKit in MacOS

Hi,

I am trying to start playing around with PDFKit on macOS 10.12.5 using XCode9beta. PDFKit should be available since 10.4. on macos. I am wondering why XCode is complaining about "import PDFKit" with "no such module PDFKit". I even tried to "import Quartz" but then the new features as presented on WWDC2017 for creating an annotation like


let newAnnotation = PDFAnnotation(bounds: CGRect(x: 10, y: 10, width: 100, height: 100), forType: .square,

withProperties: nil)


could not be interpreted as ".square" is not known.


The examples that are provided by apple do handle only iOS11, but as mentioned above, due to the developer reference, PDFKit is available since macos 10.4.

My building settings are set up for "latest macos".


Any hint is more than welcome!


Regards,

Max


Replies

First, PDFKit is not a separate module. Import Quartz to access PDFKit functions.


According to Apple's documentation on the new PDFAnnotation init method, the forType argument takes a string. You supplied the value .square, which looks like an enumeration. You need to supply a string as the forType argument. If the enumeration contains string values, use the rawValue property of the enumeration to get the string.

I copied the statement from apples PDFKit-Presentationslides. To me it seems like these new statements only work with 10.13.

If anyone ends up on this thread because they can't import PDFKit in a macOS app, especially because of "Undefined symbols", that's because the right way to do it is

Code Block
import Quartz.PDFKit

I don't know why it's not mentioned in the documentation page since the one talking about it seems to be a mirror. Anyway, you can checkout the WWDC17 video about that (first example given is with a Cocoa app).