Swift

Apple's language for building iPhone, iPad and Mac apps.

Swift is Apple's language for apps on iPhone, iPad, Mac and its other devices. It is compiled and fast, its optionals catch missing-value errors at compile time, and with SwiftUI you can build app screens in a small amount of code.

  • Intermediate
  • 8 lessons
Not started yet
Start lesson 1

Lessons

  1. Hello, SwiftWrite and run your first Swift program and learn let, var and Swift's basic types. Swift has concise syntax with no semicolons, and it compiles to fast native code.
  2. OptionalsLearn optionals, Swift's way of handling values that might be missing. A String? is a different type from a String, and the compiler makes you handle the missing case before you use it.
  3. Functions & Control FlowLearn how to write functions with argument labels, and how to branch with if and switch. Swift's switch can match ranges and patterns, so it often replaces long if-else chains.
  4. Structs, Enums & Value TypesLearn structs, enums and the difference between value and reference types. In Swift, structs are copied on assignment and are the usual choice, and enum cases can carry data.
  5. Collections & ClosuresLearn arrays, dictionaries and sets, and how to transform them with closures and map, filter and reduce, including the short $0 syntax.
  6. Errors & async/awaitLearn how to throw and handle errors and how to call asynchronous code with async/await. Swift marks both in the code: throws in a function signature and await at the call site.
  7. Your First SwiftUI AppBuild a simple counter app with SwiftUI. You describe screens as structs, and SwiftUI updates them when @State values change.
  8. Swift CheatsheetOptionals, structs, enums, closures, and SwiftUI basics on one page.

Install it on your own computer

Building iOS apps requires Xcode, which only runs on a Mac. The language itself also runs on Linux and Windows, and the Swift Playgrounds app on iPad or Mac is a good way to learn.

Bash
# Swift toolchain for Windows exists (swift.org/install),
# but you cannot build iOS apps on Windows.
winget install Swift.Toolchain

swift --version
swift run          # in a package folder

# Realistic options for iOS without a Mac:
# - Swift Playgrounds on an iPad
# - online: swiftfiddle.com

What people build with Swift

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Build iPhone, iPad, Mac, and watch apps
  • Create server-side Swift services
  • Develop command-line tools for Apple platforms
  • Write safe performance-sensitive applications

Projects to try

  1. SwiftUI journal
  2. Weather menu-bar app
  3. Core Data expense tracker
  4. Vapor web API

Common tools and packages

SwiftUIUIKitSwift Package ManagerVaporAlamofireSwift TestingXCTestSwiftLint

Well-known software

Apple platform appsFirefox iOSSignal iOSWordPress iOSLinkedIn iOSArc for macOS