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
- Go to
https://swift.org/download
- Scroll to Windows 64-bit section
- Download the latest ZIP file (e.g.,
swift-5.9.2-RELEASE-windows10.exe
) - Extract to a directory like
C:\Swift
⚙️ Add Swift to PATH (Environment Variable)
- Search for “Environment Variables” in Windows
- Click “Edit the system environment variables”
- Under “System Variables”, select
Path
and click Edit - 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.