0

I have created swift package manager. In that i have to add third party package https://github.com/danielgindi/Charts. I have added that package as dependancy in Package.swift file. It has been added and showing under package dependancies. But when i try to use that package, it is giving me error No such module 'DGCharts'. What could be the issue here?

Package file

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

    import PackageDescription
    
    let package = Package(
        name: "XYZFramework",
        platforms: [
            .iOS(.v15)
        ],
    
        
        products: [
            // Products define the executables and libraries a package produces, and make them visible to other packages.
            .library(
                name: "XYZFramework",
                targets: ["XYZFramework"]),
        ],
        dependencies: [
            // Dependencies declare other packages that this package depends on.
            // .package(url: /* package url */, from: "1.0.0"),
            .package(url: "https://github.com/danielgindi/Charts.git", .upToNextMajor(from: "5.0.0"))
        ],
        targets: [
            // Targets are the basic building blocks of a package. A target can define a module or a test suite.
            // Targets can depend on other targets in this package, and on products in packages this package depends on.
            .target(
                name: "XYZFramework",
                dependencies: []
                /*,
                resources: [Resource.process("XYZFramework/Sources/XYZFramework/Resources/XYZFramework.xcassets")]*/),
            .testTarget(
                name: "XYZFrameworkTests",
                dependencies: ["XYZFramework"]),
        ]
    )
import SwiftUI
import DGCharts

struct SwiftUIView: View {
    let chartView = PieChartView()

    var body: some View {
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
    }
}

#Preview {
    SwiftUIView()
}

In above it is giving error No such module 'DGCharts'

1 Answer 1

1

You need to add the packaged dependency in the target's dependencies list before you can use it.

.target(
    name: "XYZFramework",
    dependencies: [
        .product(name: "DGCharts", package: "Charts")
    ]
)

Sometimes, Xcode will ask you to explicitly declare the target's dependencies. You can help Xcode do this by using product(name: String, package: String? = nil)

Documentation

From: https://developer.apple.com/documentation/packagedescription/package

Sign up to request clarification or add additional context in comments.

2 Comments

Hard part is to find out the correct name for the package parameter in "product(name: String, package: String? = nil)". Sometimes it is a given in the readme file, and sometimes is nowhere to be found.
I think the easiest way to identify the products produced by a package is to check the Package.swift file. Usually, they will be listed in the 'products' section. Like the DGCharts here. github.com/danielgindi/Charts/blob/master/Package.swift For the package name I think you can use the name of that package's repository like "Charts" from github.com/danielgindi/Charts.git

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.