Introduction
Swift is Apple's language for its platforms: iPhone, iPad, Mac, Apple Watch, and Apple TV. Introduced in 2014 to replace the older Objective-C, it was designed to be safe, fast, and — unusually for a systems language — genuinely pleasant to read and write.
Even if you never ship an app, Swift teaches one idea every developer should understand: optionals.
Optionals: saying "this might be missing"
Most bugs in app development come from one cause: code assuming a value exists when it does not. Swift makes that assumption impossible to hide. A value that might be missing is wrapped in an Optional, and you must unwrap it before use.
var nickname: String? = nil
nickname = "Waqas"
if let name = nickname {
print("Hello, \(name)!")
} else {
print("No nickname set.")
}
String? means "a String, or nothing". The if let unwraps it safely: inside the block, name is guaranteed to exist. There is no way to accidentally use a missing value — the compiler will not allow it. Other languages have since copied this idea, because it works.
Structs first, classes when needed
Swift prefers structs (value types) over classes (reference types) for most data. A struct is copied when passed around, so changing one copy never surprises another part of the program:
struct Point {
var x: Double
var y: Double
}
var a = Point(x: 0, y: 0)
var b = a
b.x = 10
// a.x is still 0 — b is an independent copy
Classes still exist for things that genuinely need shared identity — a network connection, a view controller — but reaching for a struct first makes programs easier to reason about.
SwiftUI: describing interfaces, not building them by hand
Modern Apple apps are built with SwiftUI, where you describe what the interface should look like and the system keeps it in sync with your data — the same reactivity idea as Vue and React:
struct ContentView: View {
@State private var count = 0
var body: some View {
Button("Clicked \(count) times") {
count += 1
}
}
}
@State marks data the view watches; change count, and the button label updates. No manual UI updates, no outlet wiring — describe, and SwiftUI handles the rest.
Takeaway
Optionals make missing values explicit and safe, structs make data predictable, and SwiftUI makes interfaces declarative. Together they explain why Swift developers describe the language as feeling modern: it removes whole categories of mistakes before your app ever runs.
Originally published at https://practicaldevblog.blogspot.com/2026/10/swift-explained-apples-language-for.html
Top comments (0)