Skip to main content

How to use the Swift Package Manager in Replit

So, this excuse for an IDE called Replit doesn't have packages for Swift like it does for Python. We're not having that.

Step 1

Create a new Swift repl. We want to make a simple program that looks like this, using onevcat's Rainbow package.
 

Step 2

Create your Package.swift file. This file defines the products, dependencies, targets and so on for a Swift package. Check out Swift's Package Manager guide for more details.
 

Step 3

Swift Package Manager looks for your sources in the "Sources/{{Package}}" directory. For a package called Testing, move your main.swift file to "Sources/Testing/main.swift".

Step 4

Modify the .replit file to use the SPM when building and running.
 

It should look something like this. The first two lines have been changed.
 

Step 5

Smash that Run button and you should be good to go!
If you get any errors mentioning "error: PCH was compiled with module cache path" after renaming the Repl, or running from the cover page, just delete the .build/ directory and run it again.


I hope that this tutorial, showing you how to use the Swift Package Manager (or SPM) in Replit, was useful. Have a nice day!

Comments