Over the past two weeks, you’ve learned how to use SwiftUI to build beautiful, responsive user interfaces. But, so far, the “apps” you’ve built may seem a bit… boring. This is because they are completely static – meaning that they are read-only and don’t support any user interaction. Today, you will be making a big step towards making our apps interactive – learning how to write code using Swift. And how to write it well.

Gradescope

<aside> <img src="notion://custom_emoji/8c53c628-b24b-45b1-a1b6-7972159b1dca/182e7294-157f-8097-b2fc-007ac892450f" alt="notion://custom_emoji/8c53c628-b24b-45b1-a1b6-7972159b1dca/182e7294-157f-8097-b2fc-007ac892450f" width="40px" />

Answer the associated questions on Gradescope!

</aside>

What’s Swift?

<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/8c53c628-b24b-45b1-a1b6-7972159b1dca/782683d5-720f-4d03-85b3-92d7382a974b/swift-notion-blue.svg" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/8c53c628-b24b-45b1-a1b6-7972159b1dca/782683d5-720f-4d03-85b3-92d7382a974b/swift-notion-blue.svg" width="40px" />

The Swift Programming Language

</aside>

Swift is a general-purpose programming language that’s approachable for newcomers and powerful for experts.

It is fastmodernsafe, and a joy to write.

The headline from the homepage of swift.org does a pretty good job of describing Swift. But, let’s dive in a little deeper.

General-purpose language

In COMP 433, Swift will be the programming language that you use to implement the business logic for our iOS apps. But, contrary to popular belief, Swift can be used for more than just iOS development.

This is because Swift is a general-purpose programming language. This means that you can use Swift to write code for any use case: app development, scripting, machine learning, backend development, and more! Swift is maintained by a large and flourishing open-source community who are constantly finding new ways to use the language.

While Swift can be used for a never-ending list of tasks, it is – by far – used the most to build apps for Apple’s platforms. This is because the language was created by Apple to replace Objective-C, the previous language used to build apps for their platforms.

Because of this intention, Apple invests significantly into the tooling and frameworks needed to use Swift for app development, making that use case very well-supported. But, especially in the last few years, both Apple and the open source community have been working very hard to expand Swift’s usage to other domains. One very notable example of this is The Browser Company using Swift to build Arc for Windows.

Approachable & powerful

One of Swift’s core principles is “progressive disclosure” – a usability strategy where only the essential information is presented initially, but more advanced features are available as needed. This means that there is very little overhead when beginners start using the language, but as your skills develop, there are more and more powerful features available to use.

For example, like Python, you can write a Swift program with a single line and no boilerplate –

// hello.swift
print("Hello, World!")

But then, as you need to write more powerful programs, Swift has a huge list of powerful features ready for you when you need them – but you don’t need to learn about them earlier than necessary. Such features include (but aren’t limited to) –