How to rename a package's name on import

Is there any way to rename a package's name when importing it?

For example:

import Foo as SomeToolKit
1 Like

I have never tried it but I think SE-0339 Module Aliasing for Disambiguation enables this?

1 Like

Thank you, but that seems to require changing the file Package.swift.

The App manifest needs to explicitly define unique names for the conflicting modules via a new parameter called moduleAliases.

let package = Package(
 name: "App",
 dependencies: [
  .package(url: https://.../swift-game.git),
  .package(url: https://.../swift-draw.git)
 ],
 products: [
  .executable(name: "App", targets: ["App"])
 ]
 targets: [
  .executableTarget(
    name: "App",
    dependencies: [
     .product(name: "Game", package: "swift-game", moduleAliases: ["Utils": "GameUtils"]),
     .product(name: "Utils", package: "swift-draw"), 
   ])
 ]
)
1 Like