gpt4 book ai didi

objective-c - 无法在 SwiftPM 的 ObjC 模块中导入 AppKit

转载 作者:行者123 更新时间:2023-12-01 23:38:28 25 4
gpt4 key购买 nike

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

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

关于objective-c - 无法在 SwiftPM 的 ObjC 模块中导入 AppKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48240510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com