Introduction to Swift
Learn what Swift is, who created it and why, its core philosophy of safety and speed, and write your first line of Swift code.
Introduction
Swift is Apple's modern, open-source programming language for building apps across iOS, macOS, watchOS, and tvOS. It was designed to be fast like a compiled systems language while feeling as friendly and expressive as a scripting language — and it made the elimination of an entire class of bugs, caused by nil (empty) values, a first-class part of the type system.
This lesson introduces what Swift is, why it was created, the philosophy that shapes its design, and gives you your very first taste of actual Swift code.
- What Swift is and what kind of language it is (compiled, statically typed, safety-focused).
- Who created Swift at Apple, and why Objective-C was no longer enough.
- The core philosophy of safety, speed, and expressiveness that guides Swift's design.
- The key features that make Swift stand out, especially Optionals.
- What a minimal Swift program looks like.
What is Swift?
Swift is an open-source, statically typed, compiled programming language. "Statically typed" means every value's type is known and checked at compile time, catching a huge class of bugs before your app ever runs. "Compiled" means Swift source code is translated by LLVM into fast native machine code — there is no separate interpreter slowing your app down at runtime.
What sets Swift apart from most mainstream languages is how seriously it treats the absence of a value. Instead of letting any variable silently be nil (as Objective-C, Java, and many other languages allow), Swift requires you to explicitly mark a value as "optional" if it might be missing, using the `?` symbol. This single design decision, called Optionals, eliminates most null-pointer-style crashes at compile time instead of at 2am in production.
Who Created Swift, and Why
Swift was created by Chris Lattner, a software engineer at Apple who had already built the LLVM compiler infrastructure and the Clang compiler front-end that Apple's tools depended on. Lattner started sketching out the design of Swift as a personal project in July 2010, drawing inspiration from a wide range of languages including Objective-C, Rust, Haskell, Ruby, Python, C#, and CLU.
The project was later folded into official Apple work, and a growing team of Apple engineers joined Lattner to build it out over several years in near-total secrecy. Swift was announced publicly at Apple's Worldwide Developers Conference (WWDC) on June 2, 2014, and Swift 1.0 shipped a few months later alongside Xcode 6 and iOS 8. On December 3, 2015, Apple open-sourced Swift under the Apache 2.0 license and launched swift.org, extending the language beyond Apple's own platforms to Linux and, later, Windows.
The Problem Swift Was Built to Solve
Before Swift, Apple developers wrote apps in Objective-C, a language built by layering object-oriented features on top of C in the early 1980s. Objective-C inherited C's manual memory pitfalls and unsafe pointer arithmetic, had a notoriously verbose syntax with square-bracket method calls, and — critically — let messages be sent to a nil object silently, which made "this crashed because of a hidden nil" one of the most common bug categories in iOS development.
Apple wanted a language that kept Objective-C's Cocoa framework compatibility and near-C performance, while removing entire categories of runtime crashes through better compile-time checking, offering cleaner and more expressive syntax, and giving developers modern language features like closures, generics, and pattern matching without needing a totally separate runtime.
Core Philosophy
Every feature Swift has — and how it is designed — traces back to a small set of guiding principles.
- Safety first — Swift is designed to eliminate whole categories of bugs (nil dereferencing, uninitialized variables) at compile time rather than at runtime.
- Speed matters — Swift is built on LLVM and is designed to be as fast as compiled languages like C++.
- Expressive, modern syntax — closures, generics, tuples, and pattern matching are built in, not bolted on.
- Clarity over brevity — Swift favors code that clearly states its intent, embodied in the community-wide Swift API Design Guidelines.
- Interoperability — Swift was designed to work seamlessly alongside existing Objective-C code and frameworks.
Key Features at a Glance
Optionals
A type-safe way to represent "no value" (`T?`), forcing you to handle absence explicitly instead of crashing on nil.
Type Inference
Swift figures out most types automatically, so code stays concise without sacrificing type safety.
Memory Safety with ARC
Automatic Reference Counting manages memory for you without a garbage collector pausing your app.
Protocol-Oriented Design
Swift favors composing behavior through protocols and extensions over deep class inheritance chains.
Compiled & Fast
Compiles via LLVM straight to native machine code, competitive with C and C++ in benchmarks.
Objective-C Interop
Swift and Objective-C code can live side by side in the same project and call into each other.
Your First Taste of Swift
No introduction to a language is complete without seeing actual code. Here is the smallest complete Swift program — one that prints a greeting to the screen.
print("Hello, Swift!")Click Run to see what this code prints.
Don't worry about understanding everything yet. Notice, though, that unlike many languages there is no boilerplate class wrapper and no explicit `main` function required at the top level of a Swift file — you write a statement, and it runs. Deeper syntax is covered starting in the next few lessons.
Where Swift Is Used Today
Swift has become the default language for building software across Apple's entire ecosystem, and it is increasingly used outside it too.
| Platform / Use Case | What It Means |
|---|---|
| iOS Apps | The primary language for building apps for iPhone and iPad, typically paired with SwiftUI or UIKit. |
| macOS Apps | Native desktop applications for Mac, from menu bar utilities to full production apps. |
| watchOS & tvOS Apps | Apps for Apple Watch and Apple TV share the same language and much of the same tooling. |
| Server-Side Swift | Frameworks like Vapor and Hummingbird let Swift power backend web services and APIs. |
| Cross-Platform Tools | Swift compiles on Linux and Windows too, used for CLI tools and shared business logic. |
Common Mistakes
- Assuming Swift only runs on Apple hardware — the compiler and standard library are open source and run on Linux and Windows too.
- Confusing "Swift" the language with "Xcode" the IDE — Xcode is Apple's development environment, and Swift is the language it compiles.
- Thinking Swift replaced Objective-C overnight — the two still interoperate, and older Apple codebases remain in Objective-C.
- Skipping the philosophy section and jumping straight to syntax — understanding *why* Optionals exist makes the syntax click far faster.
Best Practices
- Read Swift code with the expectation that nil is always explicit — that is a safety feature, not extra ceremony.
- Install Xcode early if you are on a Mac; it bundles the Swift compiler, a REPL, and Playgrounds for quick experiments.
- Bookmark the official Swift documentation at swift.org and the Swift API Design Guidelines — both are clear and example-driven.
- Get comfortable running tiny snippets early; Swift's Playgrounds make experimentation fast and visual.
Frequently Asked Questions
No. Swift also builds macOS, watchOS, and tvOS apps, and server-side frameworks like Vapor let it power backend services too.
Yes. Apple open-sourced Swift on December 3, 2015, under the Apache 2.0 license, and development happens publicly at swift.org.
No. Swift was designed to be approachable on its own. Objective-C knowledge only helps if you need to read older Apple codebases.
Yes, completely free. The compiler, standard library, and tooling are all open source with no licensing fees.
Key Takeaways
- Swift is an open-source, statically typed, compiled language created by Chris Lattner at Apple.
- Development began as a personal project in 2010, was announced publicly at WWDC in June 2014, and was open-sourced in December 2015.
- Swift's core philosophy is safety, speed, expressiveness, and interoperability with Objective-C.
- Optionals are Swift's signature feature, forcing explicit handling of "no value" at compile time.
- Swift powers iOS, macOS, watchOS, and tvOS apps, and is expanding into server-side and cross-platform tooling.
Summary
You now know what Swift is, who built it, why it exists, and what its guiding philosophy is. You have also run your very first line of Swift code. Next, you will dig deeper into Swift's history — from its secretive origins to the major version milestones that shaped the language you'll be learning.