Search code examples
iosswiftobjective-cxcodeswift-package-manager

Unable to import Swift package that contains only Objc Code


I am trying to import a local swift package that only contains objective C files into an app using @import MyLibrary;. But it throws an error saying Module 'MyLibrary' not found. Am I missing something in the package manifest or isn't this an allowed setup?

Package.swift

import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [
            .iOS(.v12)
            ],
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]),
    ],
    dependencies: [
    ],
    targets: [
        .target(
            name: "MyLibrary"),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]),
    ],
)

enter image description here


Solution

  • Tweaking the package.swift file fixed it

    .target(
            name: "MyLibrary",
            dependencies: [],
            publicHeadersPath: "Public")
    

    add a folder called Public inside the source folder and move all the public headers there. Now the package is visible in the project