# What Swift Is and Where It Runs — Swift

Source: https://www.skillbyai.com/en/swift/f-what

> Describe Swift's goals, platforms and current language versions.

## Safe, fast and expressive

**Swift** is a compiled, statically typed language introduced by Apple in 2014 and open-sourced in 2015. It is the primary language for apps on **iOS, iPadOS, macOS, watchOS, tvOS and visionOS**, and it also runs on **Linux** and **Windows**, with growing use for server-side code and command-line tools. Swift's design goals are **safety** (no null pointer crashes thanks to optionals, bounds-checked arrays, definite initialisation, automatic memory management), **speed** (compiled to native code through LLVM) and **expressiveness** (type inference, closures, generics, protocol extensions, pattern matching). It interoperates with Objective-C and, increasingly, with C and C++. **Swift 6** (2024) introduced a language mode with **compile-time data-race safety**, typed throws and more, and later releases continue to make concurrency more approachable. Swift evolves publicly through the Swift Evolution proposal process. For UI, Apple's modern framework is **SwiftUI**, while older apps use UIKit; this course focuses on the language itself, which every Apple-platform developer needs first.

## One language, many platforms

Swift code compiles to native binaries for Apple platforms, Linux and Windows.

![A central code document icon with arrows to several device silhouettes: phone, laptop, watch, headset and a server rack.](assets/figures/swift/section-1-map.svg) — Figure 1.1 — Swift across Apple platforms and servers.

## A first Swift program

Constants, inference, interpolation and a function call.

```swift
let name = "Asha"            // constant, type inferred as String
var visits = 0                // variable, inferred as Int
visits += 1

func greet(_ person: String, times: Int) -> String {
    "Hello, \(person)! You have visited \(times) time\(times == 1 ? "" : "s")."
}

print(greet(name, times: visits))

// command line:  swift run   (in a Swift package)  or  swift hello.swift
```

## Learn the language before the UI framework

SwiftUI tutorials move fast and assume you understand optionals, structs, closures and protocols. A week on the language first makes SwiftUI far easier to follow.

**Quiz:** Which feature is central to Swift's safety against null-pointer crashes?

- [x] Optionals that make the absence of a value explicit
- [ ] Garbage collection
- [ ] Manual memory management
- [ ] Dynamic typing

*Answer:* Optionals that make the absence of a value explicit. Optionals force code to handle missing values explicitly.
