Running Swift Code on Windows: A Quick Guide for Beginners

Hi everyone ✋

If you’re eager to learn Swift programming on your Windows machine, this guide is for you. Follow these steps to set up your system and run Swift code effortlessly.

Step 1: Download Swift for Windows

Visit the Swift for Windows website at https://swiftforwindows.github.io/ and download the Swift 4.1.3 compiler, which is the officially supported version.

While there are newer release builds for Swift 5.x, they might not work for running single Swift files. If there have been updates or changes, please let me know, and I’ll be happy to provide the latest information.

 

Step 2: Installation

Once downloaded, run the Swift for Windows software. After launching, you’ll encounter this screen.

If you are wondering, yes can build and run swift code right now with little extra hassle. Here’s a quick rundown:

  1. Write Swift code in your preferred editor (e.g., Sublime Text, Atom).
  2. Save the file.
  3. Select the file in Swift for Windows 2.0.
  4. Compile.
  5. Run.

Seems easy, right? Hold on; we have an even simpler solution.

Step 3: Add Path to Environment variables

Copy the compiler path from the Swift for Windows 2.0 software window (If you can’t copy, navigate to the shown path, and copy it from there).

 

In my case, the compiler path is C:\Swift\bin. Yours may differ.

Now, follow these steps:

1. Right-click on “This PC” and go to properties.

 

2. Navigate to advanced system settings.

 

3. Go to Environment variables.

 

4. Under the system variables section,

  • Select “Path”
  • Click on the edit button

 

5. Add the Swift path

  • Click on “New.”
  • When Blank space appears, paste the copied path in the blank space.
  • Click OK

Step 4: Install VS Code

Download Visual Studio Code and proceed with the installation.

 

Step 5: Install Plugins

  1. Swift Plugin
  2. Code Runner Plugin

Step 6: Run Swift Code

Now, open Visual Studio Code, write your Swift code, and hit the run button.

 

It’s that much simple now.
Happy Coding 💻 🎵

Leave a Comment

Your email address will not be published. Required fields are marked *