Swift 5.9 and PDFKit JIT session error w/symbol dump

The following code works correctly in a Swift Playground created by Xcode 14.3.1 or Xcode 15. It outputs the page count of the one-page test pdf as 1.


import Foundation
import PDFKit

let test_PDF = ("~/Desktop/test.pdf" as NSString).expandingTildeInPath
let test_URL = NSURL.init(fileURLWithPath:test_PDF) as URL
let pdf = PDFDocument(url:test_URL)!
print(pdf.pageCount)


However, the same code outside of either Playground fails with a JIT session error: Symbols not found: when run as an interpreted (#!/usr/bin/swift) or compiled solution on Ventura 13.5.2 or 13.6 with the command line tools for Xcode 15 installed - which introduced Swift 5.9. Earlier versions of Swift worked correctly with the same code above.



I discovered that the workaround for this JIT Error and an error free execution was to make the following change:


import PDFKit


with:


import Quartz.PDFKit


or even just Quartz.



Mac mini (M2, 2023)

Posted on Sep 22, 2023 6:23 AM

Reply
6 replies

Jan 23, 2024 6:08 AM in response to Frost Land

Yes, you are right. My TabularData solution in Swift 5.9.2 works fine in a Playground, but only when I had the long shebang does it work correctly to output tabular results from a CSV to the Terminal in a standalone script.



#!/usr/bin/env DYLD_FRAMEWORK_PATH=/System/Library/Frameworks /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

// https://www.jessesquires.com/blog/2024/01/22/swift-scripting-broken-macos-14/

import TabularData
import Foundation

let defaultPath = ("~/Desktop/foo.csv" as NSString).expandingTildeInPath
let csv_url = URL(fileURLWithPath: defaultPath)
let result = try? DataFrame(contentsOfCSVFile: csv_url)
print(result!)

Jan 20, 2024 7:56 AM in response to Frost Land

Nope.


The following now works cleanly with Swift 5.9.2:


#!/usr/bin/swift

import Foundation
import Quartz

let test_PDF = ("~/Desktop/test.pdf" as NSString).expandingTildeInPath
let test_URL = NSURL.init(fileURLWithPath:test_PDF) as URL
let pdf = PDFDocument(url:test_URL)!
print(pdf.pageCount as Int)
print(pdf.string! as String)
exit(0)


Jan 23, 2024 5:32 AM in response to VikingOSX

For TabularData, this does not work, and we need the novel, sadly.

macOS 14.3, Xcode 15.2, swift 5.9.2


To be more precise, the DYLD_FRAMEWORK_PATH environment variable is required for the imports to work (at least of TabularData), and xcrun drops it. When using swift all by itself it’s actually xcrun which runs swift, so we have to put the full swift path for the variable to be in the environment when swift runs.

Swift 5.9 and PDFKit JIT session error w/symbol dump

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.