带Xcode的Swift包管理器 - 无法构建Objective-C模块

时间:2023-01-24 09:14:05

I have a swift executable package that has a dependency on objective-c library package. I'm trying to use Xcode for executable package development but I'm getting Could not build Objective-C module 'objcpackage' error while editing the swift file which imports objective-c module. Compiling works both from Xcode and also directly from command line using swift build but as soon as I open the swift file with import of that objc package the error pops up. I have used the SPM to generate xcodeproj.

我有一个swift可执行包,它依赖于objective-c库包。我正在尝试使用Xcode进行可执行包开发,但是我在编辑导入objective-c模块的swift文件时无法构建Objective-C模块'objcpackage'错误。编译既可以从Xcode运行,也可以直接从命令行使用swift构建,但只要我打开swift文件导入该objc包就会弹出错误。我使用SPM生成xcodeproj。

Clean nor clean build directory, deleting generated module map from the xcodeproj or restarting Xcode did not help.

清理或清理构建目录,从xcodeproj删除生成的模块映射或重新启动Xcode没有帮助。

I have created Objective-C package with the following:

我创建了Objective-C包,其中包含以下内容:

$ swift package init --type library

$ swift包init --type库

It contains only one header Sources/include/Foo.h:

它只包含一个头Sources / include / Foo.h:

#import <Foundation/Foundation.h>

@interface Foo: NSObject
@end

and one .m file:

和一个.m文件:

#import "Foo.h"

@implementation Foo
@end

The Swift package was created with $ swift package init --type executable.

Swift包是使用$ swift包init -type可执行文件创建的。

The Package.swift file looks like:

Package.swift文件如下所示:

import PackageDescription

let package = Package(
    name: "swiftpackage", 
    dependencies: [ .Package(url: "../objcpackage", majorVersion: 1) ]
)

The main.swift contains only:

main.swift仅包含:

import objcpackage

Xcode project was created with $ swift package generate-xcodeproj

Xcode项目是使用$ swift包generate-xcodeproj创建的

Xcode Version: 8.2.1 (8C1002)

Xcode版本:8.2.1(8C1002)

Swift Version: 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)

Swift版本:3.0.2(swiftlang-800.0.63 clang-800.0.42.1)

How can I get rid of that error?

我怎样才能摆脱这个错误?

1 个解决方案

#1


1  

This sounds like a bug that was recently fixed in the package manager (https://bugs.swift.org/browse/SR-3121). Have you tried a recent snapshot from https://swift.org/download/?

这听起来像是最近在包管理器中修复的错误(https://bugs.swift.org/browse/SR-3121)。您是否尝试过https://swift.org/download/的最新快照?

I tested the package you describe with a recent version of Swift 3.1 and it worked fine.

我用最新版本的Swift 3.1测试了你描述的软件包,它运行良好。

#1


1  

This sounds like a bug that was recently fixed in the package manager (https://bugs.swift.org/browse/SR-3121). Have you tried a recent snapshot from https://swift.org/download/?

这听起来像是最近在包管理器中修复的错误(https://bugs.swift.org/browse/SR-3121)。您是否尝试过https://swift.org/download/的最新快照?

I tested the package you describe with a recent version of Swift 3.1 and it worked fine.

我用最新版本的Swift 3.1测试了你描述的软件包,它运行良好。