Swift — Hello World
The classic hello-world in Swift — a single print — for testing highlighters, the Swift compiler, and parsers.
// The classic first program, in Swift.
print("Hello, world!")
Specifications
- Language
- Swift
- Kind
- hello-world
- Lines
- 2
- Encoding
- UTF-8
- Line Endings
- LF
What is a .swift file?
Swift (.swift) is a plain-text source file for the Swift programming language — a statically typed, compiled language from Apple used for iOS, macOS, and server development. It emphasises safety with optionals and value types, and features structs, protocols, generics, and pattern matching.
How to use this file
Use an example .swift file to test syntax highlighters, the Swift compiler, linters and formatters (SwiftLint, swift-format), and parser or language-detection tooling.
Related files
- swiftSwift — Task list (struct, protocol, optionals)A realistic Swift snippet with an enum, a protocol, a struct with a computed property, optionals and optional binding, and higher-order functions — for testing highlighters, the Swift compiler, SwiftLint, and parsers.

- cC — Hello WorldThe classic hello-world in C — an include, main, and printf — for testing highlighters, C compilers, and parsers against the canonical first program.

- cC — Linked list (structs, malloc, pointers)A realistic C program: a singly linked list with a typedef struct, malloc/free memory management, pointer walking, and error handling — for testing highlighters, compilers, and static analysers.

- cppC++ — Hello WorldThe classic hello-world in C++ — iostream and std::cout — for testing highlighters, C++ compilers, and parsers.

- cppC++ — Series (class template, STL)A realistic C++ snippet with a class template, STL algorithms (max_element, accumulate), std::move, and range handling — for testing highlighters, g++/clang++, and parsers against real templates.

- cssCSS — Component styles (variables, flexbox, keyframes)A realistic component stylesheet using custom properties, flexbox, a fluid clamp() font size, color-mix(), a keyframe animation, and a media query — for testing CSS parsers, linters (stylelint), and highlighters.

Generated by generation/code_samples.py. Free for any use, no attribution required — license.