我有一个带有两个目标(A
和B
)的框架,文件结构如下:
FooFramework
|__ A
|__ Foo.swift
|__ Bar.swift
|__ Foobar.swift
|__ B
|__ Barfoo.swift
B
基本上有一个A
's 源的子集(其中B
设置为目标),例如B
只使用Foo.swift
and Bar.swift
,但不使用Foobar.swift
.
现在我有一个需要框架A
和B
(在单独的目标中)的应用程序。
在这一点上,我不确定如何设置Package.swift
文件以使此设置正常工作。每当我打开Package.swift
inXcode
并尝试构建框架B
时,编译器都会抱怨 in 缺少类型Barfoo.swift
,因为它们包含在Bar.swift
.
这就是我设置Package.swift
文件的方式:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "Framework",
platforms: [
.iOS(.v11),
.macOS(.v10_15)
],
products: [
.library(
name: "A",
targets: ["A"]),
.library(
name: "B",
targets: ["B"]),
],
dependencies: [
.package(name: "Dependency", url: "https://github.com/...", .exact("1.0.0"))
],
targets: [
.target(
name: "A",
dependencies: [
"Dependency",
],
path: "A",
exclude: [
"Info.plist",
],
resources: [
.process("fonts"),
]
),
.target(
name: "B",
dependencies: ["A"],
path: "B",
exclude: [
"Info.plist",
],
resources: [
.process("../A/fonts"),
]),
.testTarget(
name: "ATests",
dependencies: ["A"],
path: "ATests",
exclude: [
"Info.plist"
]
)
]
)
相关来源,但不幸的是没有帮助: