Module 1: Introduction to Swift & Setup (Windows)

Module 1: Introduction to Swift & Setup (Windows)

AI Reading

Quick summary of this article

This module teaches you how to install and run Swift on a Windows computer without needing a Mac or Xcode. Swift is a modern, fast, and safe programming language from Apple used for building apps and server software. You will learn to set up Swift, run code interactively, create scripts, and compile programs into executable files.

  • Download the Swift installer from swift.org, extract it to a folder like C:Swift, and add C:Swiftbin to your system PATH variable.
  • Verify installation by running swift --version in your terminal; you should see version 5.9.2 for Windows.
  • Use the Swift REPL by typing swift to run interactive code, or create a .swift file and run it with swift filename.swift.
  • Compile your Swift script into a standalone executable using swiftc hello.swift -o hello.exe, then run it with ./hello.exe.
  • If you get errors, ensure Swift is in your PATH, install Visual C++ Redistributable for missing DLLs, and try using CMD or VS Code terminal if REPL won't launch.

In this module, you’ll learn how to set up Swift on a Windows machine and run your first Swift program without needing a Mac or Xcode. It includes a detailed guide, example codes, and practical exercises to ensure you’re ready to start coding in Swift confidently.

🔍 What is Swift?

Swift is a modern, powerful, and open-source programming language developed by Apple. It is used to build iOS, macOS, and even server-side applications. Swift is designed to be safe, fast, and expressive.

  • Modern syntax and readability
  • Type safety and error handling
  • Cross-platform support (Linux, Windows)
  • Blazing fast like C-based languages

🖥️ Installing Swift on Windows

  1. Go to https://swift.org/download
  2. Scroll to Windows 64-bit section
  3. Download the latest ZIP file (e.g., swift-5.9.2-RELEASE-windows10.exe)
  4. Extract to a directory like C:\Swift

⚙️ Add Swift to PATH (Environment Variable)

  1. Search for “Environment Variables” in Windows
  2. Click “Edit the system environment variables”
  3. Under “System Variables”, select Path and click Edit
  4. Add new path: C:\Swift\bin

Restart your terminal and check with:

swift --version

Expected output:

Swift version 5.9.2 (swift-5.9.2-RELEASE) Target: x86_64-unknown-windows-msvc

🧪 Run Swift in CLI (REPL)

swift

Try typing this inside REPL:

// Interactive print("Hello from Swift REPL!")

✍️ Create Your First Swift Script

Create a file hello.swift with this content:

// hello.swift print("Hello, Swift on Windows!")

Run it using:

swift hello.swift

Output:

Hello, Swift on Windows!

🧑‍💻 Compile Swift to EXE

swiftc hello.swift -o hello.exe ./hello.exe

🧩 Common Errors & Fixes

Issue Solution
swift not recognized Ensure Swift’s bin folder is in PATH
Missing DLLs Install Visual C++ Redistributable
REPL not launching Try CMD or VS Code terminal

✅ Exercises

  • Create a greet.swift file that prints your name.
  • Run Swift REPL and try 2 + 5 * 10
  • Test variables:
    let name = "Alice" print("Hi, \(name)")
  • Compile it using swiftc

🎯 Summary

You now know how to install Swift on Windows, run scripts, use the REPL, and compile programs. You’re officially ready to start learning Swift in depth. Next, we’ll explore variables, constants, and Swift’s data types in Module 2.

Leave a Reply

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