Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

hello-world-swift

Hello, World in Swift

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Hello, World in Swift: the syntax, patterns, and safety habits you need before advancing in Swift.

Teams still ship Hello, World in Swift in Swift codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Hello, World in Swift in contexts like: iPhone/iPad/Mac apps, server-side Swift (niche), and Apple toolchain projects.

Write Swift in main.swift with print(), click Run on server—the dev runner swiftc compiles and runs the binary (requires Swift toolchain, typically macOS; LEARNING_RUNNER_ENABLED=true). Also use print() only—UIKit and SwiftUI require Xcode projects, not this single-file sandbox.

When you can explain the previous lesson's ideas without copying starter code.

Swift programs can start with top-level statements in a single file—no boilerplate class required for CLI scripts. Output uses print(), similar to println in Kotlin or print() in JavaScript (console).

Minimal program

print("Hello, World")

print writes a line to stdout with a trailing newline. Semicolons are optional; Swift infers types and prefers clear, readable expressions.

Compared to Java and C#

Java requires public class Main with public static void main. C# often uses top-level statements in modern projects. Swift CLI scripts favor top-level code or an @main attribute on a struct.

Important interview questions and answers

  1. Q: What prints text in Swift?
    A: print(), debugPrint(), and string interpolation with \(value).
  2. Q: Must every Swift file declare a class?
    A: No—top-level functions, types, and statements are idiomatic in scripts and playgrounds.

Self-check

  1. Which function prints to stdout in lessons?
  2. Are semicolons required at line ends?

Tip: Top-level print() needs no class wrapper—unlike Java public class Main.

Interview prep

What prints text?

print(), debugPrint(), and string interpolation with \(value).

Entry point?

Top-level statements or @main on a struct.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • @main attribute?
  • import Foundation?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump