无法在 SwiftPM 的 ObjC-module 中导入 AppKit

Cant import AppKit in ObjC-module of SwiftPM

我尝试使用以下代码在 Swift-Packet 的模块的 Header 中导入 AppKit:

#import <AppKit/AppKit.h>

但是编译器抛出了这个错误:

fatal error: 'AppKit/AppKit.h' file not found

我是否应该以某种方式在包的 Package.swift 文件中将其指定为依赖项?

提前致谢

迈克尔

请注意 Swift 程序包管理器 (SPM) 适用于服务器端 Swift,不适用于客户端。具体来说,AppKit 可能没有移植到服务器端 Swift,因此您无法将 AppKit 与 SPM 一起使用。 AppKit 是 Objective-C 运行时的一部分。 SPM 在构建期间不考虑 Objective-C 运行时。

来自swift.org, Platform Support

Our goal is to provide source compatibility for Swift across all platforms, even though the actual implementation mechanisms may differ from one platform to the next. The primary example is that the Apple platforms include the Objective-C runtime, which is required to access Apple platform frameworks such as UIKit and AppKit. On other platforms, such as Linux, no Objective-C runtime is present, because it isn’t necessary.

The Swift core libraries project aims to extend the cross-platform capabilities of Swift by providing portable implementations of fundamental Apple frameworks (such as Foundation) without dependencies on the Objective-C runtime. Although the core libraries are in an early stage of development, they will eventually provide improved source compatibility for Swift code across all platforms.

我刚刚通过链接 Xcode 中的这个框架解决了这个问题。 我不知道如何在 Package.swift 文件中指定它,但知道它有效。

此致