AnatomyOf

Anatomy of a Swift file

example.swift
1import Foundation
2
3struct Greeting {
4 let name: String // Constant (immutable)
5}
6
7extension Greeting {
8 func shout() -> String {
9 "HELLO, \(name.uppercased())!"
10 }
11}
12
13let greeting = Greeting(name: "Alice")
14print(greeting.shout())
15
16for i in 1...3 {
17 print("Attempt \(i)")
18}
Swift is a powerful, general-purpose, multi-paradigm programming language for Apple platforms and beyond, known for its safety, speed, and expressive syntax.