How to Write Your First Program in Swift 6.4.2? 2026 Beginner Tutorial

The Swift 6.4.2 announcement identifies the toolchain version this tutorial covers. Start by checking the official installation instructions for your operating system, then create and run a small command-line program. You can practice Swift on Windows or macOS; prepare a Mac only when your course actually requires Xcode or another Apple-platform task.

Who this is for: Students who are new to Swift and want to run a first program.
Windows users checking whether they can practice Swift before getting a Mac.
Learners who need to distinguish language exercises from an iOS app assignment.

Last updated November 11, 2026. The version and setup guidance was checked against the Swift 6.4 release information, the platform installation instructions, and Apple’s current Xcode requirements.

01 Set the target: a Swift exercise, not an iOS app

A first program is a short set of instructions that your computer builds and runs. For this lesson, the target is a Swift command-line program: it runs in a terminal and prints text. It does not create an iPhone app, open an iOS simulator, or prove that your computer is ready for an Xcode course.

That distinction matters when you plan your setup. Swift is the programming language. A toolchain is the collection of tools that lets your computer compile and run Swift code. Xcode is Apple’s development environment, which includes a Swift toolchain and tools for Apple-platform work. They are related, but they are not interchangeable labels for the same setup.

If your current assignment is about variables, functions, or simple text output, begin with the official toolchain for your operating system. If the assignment asks you to build a SwiftUI app, use an iOS simulator, or submit an Xcode project, check those requirements separately. Do not treat a successful terminal exercise as proof that an iOS build will work.

Can a Windows computer run a small Swift program?

Yes. The official Windows installation guide provides a Windows path for installing Swift. Follow its current stable-toolchain instructions for your computer rather than looking for an Xcode installer. Xcode is an Apple development environment; the Windows Swift setup is for Swift language work and does not turn Windows into an Xcode or iOS simulator environment.

Before you start, check your course instructions. A Swift syntax exercise may be fine on Windows, while a project that must open in Xcode needs a separate plan. If the course requires an Apple-platform build, ask whether your school provides a Mac or whether you need access to another Mac environment.

02 Choose the official toolchain for your computer

Use the installation page for the operating system you have now. The instructions can change, so check the current stable release and follow the platform-specific steps as written. A development snapshot is not the same thing as the stable toolchain specified by your course.

Your current computer Starting route What to verify before class work
Windows Follow the official Windows installation instructions Confirm that the installed Swift command works in the terminal. Check whether your course needs only language exercises or also Apple-platform tools.
macOS, using a standalone Swift toolchain Follow the macOS package installation guide Check which Swift version your terminal actually runs. A standalone toolchain and the one included with Xcode may differ.
macOS, using Xcode Check Apple’s Xcode system requirements and the course’s required setup Verify that your macOS version is supported by the Xcode version your course expects. Then check the active Swift version in Terminal.

On macOS, Xcode includes a Swift toolchain. You can also install a standalone Swift toolchain using the official macOS instructions. Do not assume that these installations provide identical versions, or that your terminal automatically uses the one you intended. When a course specifies a version, verify the active version rather than relying on the name of an installed app.

The Windows manual installation requirements are useful if you need to check the specific requirements for that route. Start with the regular platform guide if you are new to this. If a command is missing, inspect the instructions and your terminal environment before installing another copy. Repeating an installation without checking the active command can leave you unsure which toolchain your shell is using.

Course version check: If your instructor names a Swift version, record it before you install anything. If your terminal reports a different version, pause and compare the course requirement with the official installation instructions. Do not assume that changing toolchains is necessary until you know which one is active.

03 Create a small executable project

Swift’s command-line guide uses Swift Package Manager to set up a simple executable project. A package is a project folder with a predictable structure and files that describe the program. For a first exercise, you do not need to understand every file. You need to know where the project lives and where its code goes.

Open a terminal, move to a folder where you want to keep your coursework, and follow the Swift command-line getting-started guide. Use its project-creation command and choose an executable template. The exact project name is up to you; pick one that is easy to recognize, such as FirstSwiftProgram.

The generated folder separates program code from package configuration. The Sources folder holds the source code. A source file is the text you write for the computer to compile. In the executable template, the guide shows the program entry point: the place where execution begins. The package manifest describes the package so Swift Package Manager knows how to build it.

A useful first edit is to change the starter output to a short message of your own. Keep the change small. The aim is to check that the toolchain can read, build, and run your code—not to learn every Swift feature in one sitting. Save the file in the generated source location, not in a separate document that the package does not build.

For example, you can make the program print a greeting and then add one small change, such as printing a second line. Run it again after each edit. If the output changes as expected, you have confirmed a basic edit-build-run cycle.

04 Run the program and verify what happened

A build turns source code into a program the computer can run. The command shown in the official command-line guide builds and runs the executable package. In a terminal, first check the active Swift version with:

swift --version

Compare the result with your course requirement. Then use the run command from the official SwiftPM guide in the project folder. Read the terminal output: a successful run should display the text your program prints. The command does more than open a text file; it asks the Swift tools to build and launch the program.

Use this checklist before you move on:

  • [ ] I used the official installation instructions for my operating system.
  • [ ] I checked which Swift version the terminal reports.
  • [ ] I created the executable project using the official command-line guide.
  • [ ] I edited the generated source file inside the project folder.
  • [ ] I ran the project from its folder and saw my expected output.
  • [ ] I saved the project somewhere I can find again for class.

If the terminal says that swift cannot be found, first confirm that the installation completed and that you opened a new terminal session if the instructions require one. Then check whether the command is available in that terminal. On macOS, verify that the shell is using the toolchain you intended; having Xcode or a standalone toolchain installed does not, by itself, tell you which version the terminal is using.

If the command runs but reports an unexpected version, compare it with the course requirement and the platform-specific installation guide. Avoid installing another toolchain as a guess. If the program fails to build, read the first error message and check that you are in the project folder and edited the generated source file. A missing file or an incorrect working folder can look like a Swift language problem when it is actually a project-location problem.

What is the difference between a Swift toolchain and Xcode?

The toolchain provides the Swift tools used to check, build, and run Swift code. Xcode is Apple’s development environment and includes a Swift toolchain alongside tools used for Apple-platform development. A standalone Swift toolchain can be appropriate for language practice, but it does not provide the full Xcode workflow.

On a Mac, do not assume the standalone toolchain and Xcode’s bundled toolchain report the same version. Check the version your terminal uses and check the Xcode and macOS requirements for the course. On Windows, use the official Swift installation route for language exercises; it does not provide Xcode.

05 Match your next task to its actual environment

After your first program runs, classify the next assignment before changing your setup. A language exercise may need only Swift and a terminal. A project with dependencies may need package-resolution access and the versions specified by your instructor. An Apple-platform assignment may require Xcode and a compatible macOS environment.

Next course task What your first successful program confirms What still needs checking
Swift syntax or command-line exercise Your chosen toolchain can run a basic executable Course version, project instructions, and any required packages
A package-based Swift project The basic build-and-run path works Dependency instructions and the project’s required toolchain
SwiftUI or iOS app work Only that a command-line exercise worked Xcode availability, macOS compatibility, and simulator requirements
Assignment submission through Xcode Not that the project opens or builds in Xcode The required project format, Xcode version, and course submission steps

A command-line program succeeding does not mean you have prepared an iOS simulator. Check Apple’s current Xcode system requirements for the Xcode version your course specifies. Then compare those requirements with the Mac environment you can actually use. If the course does not yet require Xcode, you can keep learning Swift without treating a Mac as a prerequisite.

How do you move from a command-line program to iOS development?

Use the assignment as the decision point. If the next task asks for an Xcode project, a SwiftUI interface, or an iOS simulator, you need to verify access to a compatible Mac and the required Xcode version. If it continues with language exercises, keep using the Swift setup that meets the course’s stated version and project requirements.

Check before an iOS assignment Where to verify it Action if it does not match
The required Xcode version Course instructions and Apple’s Xcode requirements Ask the instructor which version is acceptable before changing systems
macOS compatibility Apple’s system requirements for that Xcode release Use a Mac that meets the requirement or ask about an approved alternative
Simulator or build task The assignment’s acceptance criteria Do not count a terminal-only Swift run as completion
Project and submission format Course instructions Test the actual project in the required environment before the deadline

A common mistake is to solve a different problem from the one the assignment asks. A Swift command-line exercise tests basic language setup. An iOS assignment tests a wider toolchain, project, and platform workflow. Keep those checks separate, and you will know what is ready and what still needs access or verification.

06 Choosing a Mac environment for Apple-platform coursework

If your current setup is Windows, your options may include using a school Mac, arranging access to a Mac you already have, or using a remote Mac for a task that needs macOS. Each choice has a different constraint. A school computer may be available only at certain times. A local Mac requires access to the physical machine. A remote environment depends on its actual system, tools, access method, and the requirements of your course.

Before relying on any Mac environment, check the Xcode version and macOS compatibility against the assignment. Confirm how you will connect, whether you can access the project files you need, and whether the environment supports the task you plan to submit. Do not assume that “Mac access” automatically means a particular simulator, Xcode release, or course configuration is available.

For a short language exercise, these checks may be unnecessary: use the Swift toolchain that fits your computer and course. For a course that has moved into Xcode, compare your available setup with the assignment before you commit to it. If you are considering a temporary remote environment, you can review CALMVPS plan information and the available Mac access options, then verify the listed conditions against your course task.

The practical choice is not “Swift means you must buy a Mac.” It is “this specific assignment needs tools that my current computer may not provide.” Windows is useful for supported Swift language practice, but it cannot run Xcode. A school Mac can depend on access hours, and buying hardware may be more than you need for a temporary course requirement. If you only need a Mac for a defined Xcode or iOS task, renting a Mac from CALMVPS can give you a remote macOS environment without making a Mac purchase a prerequisite for learning Swift. Check the current access and environment details before choosing it; if your work requires a local physical interface or sustained access beyond the listed terms, a remote rental may not fit.