Ternary operator in Swift explained
Published on: July 7, 2025Tons of languages have support for ternary expressions. In this post we learn what ternaries look like in Swift, and when we can replace them with if expressions.
Read postTons of languages have support for ternary expressions. In this post we learn what ternaries look like in Swift, and when we can replace them with if expressions.
Read postIn an earlier article, I explained how variables are defined in Swift using let and var. Both constants (let) and variables (var) in Swift always have a type; it’s what makes Swift a strongly typed language. For example, we could define a String variable like this: // the compiler will know myString is a String […]
Read postlet and var are two ways to declare properties in Swift. Let’s explore their uses, and how their behavior will change depending on where they’re used.
Read postCollections are a key component in any programming language. We often refer to collections as Array or Set but there are several other kinds of collections in programming like String (often a collection of type Character) and ArraySlice (referring to a part of an array). In this post, I’d like to explore two of the […]
Read postIn Swift, we sometimes want to assign a property based on whether a certain condition is true or false, or maybe based on the value of an enum. To do this, we can either make a variable with a default value that we change after checking our condition or we define a let without a […]
Read postSwift comes with types of objects that we can use to write type declarations. They all have their own distinct features, upsides, and downsides. In this post I’d like to zoom in on the enum type so you can get a sense of what enums are, and when they can be useful. In this post […]
Read postSometimes, we write code that needs set some state or perform some work at the start of a function and at the end of that same function we might have to reset that state, or perform some cleanup regardless of why we’re exiting that function. For example, you might have a function that creates a […]
Read postIn Swift, we can use computed properties to derive a value from other values defined on the same object. Being able to do this is super convenient because it means that we don’t have to manually make sure that we update derived properties every time one of the “source” values changed. We’ll just recompute the […]
Read postIn Swift, we can use the case keyword in multiple places. Most commonly, a case is used in switched but since you’re here, you might have seen a case in combination with an if statement. In this post, we’ll explore different places where we can use the case keyword to perform something called pattern matching […]
Read postSometimes when you’re programming you have some properties that are pretty expensive to compute so you want to make sure that you don’t perform any work that you don’t absolutely must perform. For example, you might have the following two criteria for your property: The property should be computed once The property should be computed […]
Read postLearn everything you need to know about Swift Concurrency and how you can use it in your projects with Practical Swift Concurrency the video course. It contains:
The course is available on Teachable for just $89
Enroll now