Search code examples
swiftpackage-managersswift-package-manager

Swift Package Compiler Issue


I have a Project has 4 Swift Package Dependencies. Package A, B, C, D. Each package uses the previous packages as dependencies.

I'm facing an issue where Package D is having issues compiling due to do errors inside Package B that don't actually exist. (Cannot find type 'CustomType' in scope) As Package B and the xcode project I'm using the packages in both work fine.

This is preventing me from working efficiently because the complier wont work inside Package D.

I've tried deleting derived data, cleaning the build folder, reseting package cache and none of this has worked. I'm assuming I'm doing something wrong, but I have no idea what it is.

let package = Package(
    name: "PackageD",
    defaultLocalization: "en",
    platforms: [
        .iOS(.v13),
        .macOS(.v10_15)
    ],
    products: [
        .library(
            name: "PackageD",
            targets: ["PackageD"]),
    ],
    dependencies: [
        .package(url: "PackageA", "0.0.1"..<"1.0.0"),
        .package(url: "PackageB", "0.0.1"..<"1.0.0"),
        .package(url: "PackageC", "0.0.1"..<"1.0.0"),
    ],
    targets: [
        .target(
            name: "PackageD",
            dependencies: [
                "PackageA",
                "PackageB",
                "PackageC"
            ],
            resources: [.process("Resources")]
        ),
    ]
)

Solution

  • It looks like there were a few different structs that required the use of UIKit. Which mean that UIKit needed to be able to be imported. Which wasn't an issue in the xcode project, but was an issue in the package that was built upon other packages.

    Adding #if canImport(UIKit) and #endif to all the files that required it solved the issue.