Swift is a compiled, statically typed programming language introduced by Apple in 2014 as the successor to Objective-C for its platforms. It is open source and also runs on Linux and Windows, though it is used mostly for iOS, iPadOS, macOS, watchOS and tvOS apps.
Why it matters
Swift is the main language for native Apple apps, typically paired with the SwiftUI or UIKit frameworks. It was designed for safety: variables must be initialized before use, integer overflow traps instead of silently wrapping, and optionals make the possible absence of a value explicit in the type. It manages memory with automatic reference counting rather than a tracing garbage collector.
Example
let input: String? = "42"
if let text = input, let n = Int(text) {
print(n + 1) // 43
} else {
print("not a number")
}
String? is an optional that may hold nil. if let unwraps it safely only when a value exists.
Common mistakes
- Force-unwrapping optionals with
!, which crashes the app when the value is nil. - Creating retain cycles between closures and objects, leaking memory.
- Doing UI updates off the main thread.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.