5

Workaround: Swift scripts importing Cocoa frameworks broken on macOS 14

 7 months ago
source link: https://www.jessesquires.com/blog/2024/01/22/swift-scripting-broken-macos-14/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Workaround: Swift scripts importing Cocoa frameworks broken on macOS 14

22 January 2024

On macOS 14 Sonoma there is a regression in Swift 5.9 which causes Swift scripts that import Cocoa frameworks to fail. This issue was first reported by @rdj. I discovered it myself shortly after. There is a ticket open at #68785 on the main Swift repo on GitHub to track the issue.

Considering the following Swift script:

#!/usr/bin/swift

import AppKit
import Foundation

NSPasteboard.general.clearContents()
NSPasteboard.general.setString("Hello, Swift!", forType: .string)

print("Hello, Swift!")

You can run directly from the command line:

$ ./hello.swift
Hello, Swift!

On macOS 13 and earlier, this works. Unfortunately, on macOS 14 it now fails with an error: “JIT session error: Symbols not found”.

JIT session error: Symbols not found: [ _OBJC_CLASS_$_NSPasteboard, _NSPasteboardTypeString ]
Failed to materialize symbols:

[...]

The current workaround (also posted by @rdj) is to update the shebang, #!/usr/bin/swift, by replacing it with the following:

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

Note: you must also have Xcode installed for this to work.

I’ve verified that this does indeed fix the problem!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK