Use two packages with same name in Swift

For example, there are two packages, with same package name, with different functionality, from different site urls: site1-com, site2-com respectively.

What can I do if I need to use both packages in my code at the same time.

//Package-swift

.package(name: "PlayingCard", url: "site1-com/playingcard-git", from: "1-0-0"),

.package(name: "PlayingCard", url: "site2-com/playingcard-git", from: "1-0-0"),

I know that Golang has very smart ImportDecl, so I can give them different alias names by changing my own code . Don't know how to do in Swift.

//Golang 1.15

import Chinese_PlayingCard "site1-com/playingcard-git"

import American_PlayingCard "site2-com/playingcard-git"

Thank you

There is no convenient solution yet. You will have to fork one of the dependencies and change its name, or add it as a submodule and point to its sources as an internal target.

For now it is good practice to make sure packages and targets have names that are likely unique, which can be done by including a prefix identifying the organization. (e.g. swift-numerics and TSCBasic instead of just numerics and Basic.)

Terms of Service

Privacy Policy

Cookie Policy