Swift is Apple's modern, type-safe programming language for iOS, macOS, watchOS, tvOS, and visionOS development, introduced in 2014 to replace Objective-C. Designed with protocol-oriented programming at its core, Swift combines the performance of compiled languages with the expressiveness of scripting languages while prioritizing safety through features like optionals, strong typing, and Swift 6's compile-time data-race safety. A key mental model: Swift encourages value types (structs) over reference types (classes) for better performance and predictability β think "copy-by-default" rather than "share-by-reference," which fundamentally shapes how you architect Swift applications.
What This Cheat Sheet Covers
This topic spans 26 focused tables and 188 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Type System Fundamentals
| Type | Example | Description |
|---|---|---|
struct Point { var x: Int var y: Int} | β’ Value type β copied on assignment or when passed β’ preferred for most data models. | |
class Person { var name: String init(name: String) { self.name = name }} | β’ Reference type allocated on the heap β shared when assigned β’ supports inheritance and deinitializers; use when shared mutable state or identity is needed. | |
enum Status { case success case failure(Error)} | β’ Value type for a group of related values β’ supports associated values and raw values; enables exhaustive pattern matching. |