9

I have a framework with two targets (A and B) with the following file structure:

FooFramework
|__ A
     |__ Foo.swift
     |__ Bar.swift
     |__ Foobar.swift
|__ B
     |__ Barfoo.swift

B basically has a subset of A's sources (where B is set as a target), e.g. B only uses Foo.swift and Bar.swift, but not Foobar.swift.

Now I have an app that needs both framework A and B (in separate targets targets).

At this point I'm unsure how to setup the Package.swift file for this setup to work. Whenever I open the Package.swift in Xcode and try to build framework B, the compiler is complaining about missing types in Barfoo.swift, because they are included in Bar.swift.

This is how I've setup the Package.swift file:

// 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"
            ]
        )
    ]
)

Related sources, but unfortunately unhelpful:

2
  • Did you ever find a solution? Commented Oct 5, 2022 at 19:29
  • 1
    @SamDoggett Unfortunately, not. We build the other targets as XCFrameworks and manually add them to the app. Commented Oct 11, 2022 at 6:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.