Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to Swift  ›  Lesson

What Swift Is and Where It Runs

What is Swift? 12 minSwift is a compiled, type-safe, open-source language from Apple that runs on Apple devices, servers and more, and SwiftUI is a framework written in it.

What Swift Is and Where It Runs

You want to build Sprout, a small habit tracker: a list of habits, a streak for each, a tick when you finish one today. Before you can draw a single screen of it, you need the language those screens are written in. That language is Swift, and knowing what kind of language it is tells you how it will behave.

The rule

Swift: a compiled, type-safe language from Apple, now open and everywhere.

Take the rule one piece at a time.

  • Compiled. Before Sprout runs, a compiler turns your Swift source into machine code for the device. Many mistakes are caught at that moment, on your desk, not later on a user's phone.
  • Type-safe. Every value has a type (a whole number, some text, a true/false) and Swift refuses to mix them by accident.
  • From Apple. Apple announced Swift in 2014 as the modern language for its platforms, and it is the language SwiftUI is designed for.
  • Open and everywhere. Since late 2015 Swift has been open source. It runs on Apple devices, on Linux and Windows, on servers, and increasingly on small embedded chips and in WebAssembly.

Here is the smallest piece of Sprout, written in SwiftUI. You will understand every word of it by the end of this course:

import SwiftUI

struct TodayView: View {
    let habitCount = 3

    var body: some View {
        Text("You have \(habitCount) habits today")
    }
}

SwiftUI is not a separate language. It is a framework, a library of ready-made building blocks, written in Swift and used from Swift. Learn Swift well and SwiftUI becomes a matter of learning which blocks exist.

The shortcut

When you meet any claim about Swift, sort it into one of the four words of the rule: compiled, type-safe, Apple, open. Almost every "why does Swift do that?" question answers itself once you know which of the four it comes from.

Placing Sprout in the Swift worldStep 1 of 4
  1. Where does Sprout run first?

    On iPhone. That is an Apple platform, so Swift plus SwiftUI is the natural choice.

A common mix-up is thinking Swift only works on iPhones. The Apple part explains where it began; the open part explains where it can go.

Drills

Answer fast — trust the rule.

quick drill

What is SwiftUI?

quick drill

Sprout accidentally tries to add a piece of text to a number. When is this usually caught?

quick drill

Which of these can NOT run Swift code today?

quick drill

Which part of the rule explains why you can write a web server for Sprout in Swift?

Remember

  • Swift is a compiled, type-safe language from Apple, open source since 2015.
  • Sort any Swift fact under compiled, type-safe, Apple or open.
  • SwiftUI is a framework written in Swift, not a separate language.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhere Swift fits

A friend says: 'SwiftUI is the new language that replaced Swift, and it only runs on iPhones.' Correct both halves of that sentence using what you know about Swift and SwiftUI.