Swift Hello World Program

Writing Your First Swift Program

Create a file named hello.swift. In Swift, file naming is flexible, but we’ll use hello.swift for clarity.

import Foundation

print("Hello, World!")
Hello, World!

Running the Program

If you're using a local environment like Terminal with Swift installed, run:

swift hello.swift

What happens during execution?

  • The Swift interpreter reads and executes the source code.
  • print("Hello, World!") sends output to the console.

You’ve successfully executed your first Swift program!

Common Issues to Watch For

  • Missing quotes: Make sure strings are enclosed in double quotes.
  • No semicolons needed: Swift doesn’t require semicolons at the end of lines (unless multiple statements are on one line).
  • Correct casing: Swift is case-sensitive. Print is not the same as print.
Mallikarjuna Mallisetty, author
About the author

Mallikarjuna Mallisetty

General programming

Mallikarjuna shares practical programming tutorials and foundational concepts designed to help developers learn by building and experimenting.

View LinkedIn profile ↗