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
Question marked as Top-ranking reply

Posted on Jan 22, 2024 4:27 PM

The following shebang also works without writing a novel in its place per that link you provided:


#!/usr/bin/xcrun --sdk macosx swift


Tested: macOS 14.3 and Swift 5.9.2.

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 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.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

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 Account.