Swift Classes & Inheritance

Classes are a fundamental concept in Object-Oriented Programming (OOP) and a cornerstone of Swift. In OOP, we model complex systems by creating “objects”—self-contained units that bundle data (properties) and behavior (methods). A class is the blueprint for creating these objects. Unlike structures, classes have two key characteristics: Inheritance: A class can inherit functionality from a parent class, allowing you to build hierarchies of related types. Reference Semantics: Classes are reference types. When you pass a class instance around, you’re passing a reference to the same underlying object in memory. Let’s look at a basic class: ...

Install Xcode Command Line Tools

Need to install Xcode Command Line Tools? You’re probably here because you ran git, clang, or another development command and got an error saying the command wasn’t found. The command line tools are essential for iOS development, even if you’re not using the full Xcode IDE. Here’s how to get them installed quickly. Install via Terminal (Recommended) The fastest way is using Terminal. Open Terminal and run: xcode-select --install This triggers a popup dialog asking if you want to install the command line developer tools. Click “Install” and wait for the download to complete. ...

Swift Structures

Let’s talk about structures, or structs as they’re known in code. Structures are a fundamental building block in Swift. They are versatile and widely used, from simple data containers to more complex types with their own behavior. What are Structures? A structure is a way to group related values together into a named type. Think of it like a blueprint for creating structures that hold specific kinds of data. For example, you could define a struct to represent a 2D point with x and y coordinates, or a struct to hold information about a book, like its title, author, and pageCount. ...

Swift Enumerations

Enums provide a way to define a common type for a group of related values. Enums create distinct cases for these values. Then you can work with, switch over and iterate through these distinct cases, making your code much more clear. What are Enumerations? Think of enums as a way to create your own custom set of options. For example, the days of the week, the suits in a deck of cards, or the different states an application can be in. ...

How to Control the Status Bar in iOS Simulator

Need to quickly change the iOS Simulator’s status bar for screenshots or testing? You can do it with the simctl command-line tool. Here’s a quick look. The Basic Command The core command to manipulate the status bar is: xcrun simctl status_bar <device> override <options> <device>: Use booted for the currently running simulator, or a specific simulator UDID (get a list with xcrun simctl list devices). <options>: These are key-value pairs for what you want to change. Common Status Bar Overrides Here are some of the most common things you’ll want to do: ...

SwiftUI Stacks (HStack, VStack, ZStack)

SwiftUI provides three basic containers for arranging views: HStack, VStack, and ZStack. These stacks are used for creating simple and complex user interfaces. Let’s see how they work. VStack: Arranging Views Vertically A VStack (Vertical Stack) arranges its child views in a vertical line, one on top of the other. Example: VStack { Text("Top Item") Text("Middle Item") Text("Bottom Item") } This will display three text views stacked vertically. By default, views within a VStack are centered horizontally. You can control the alignment using the alignment parameter: ...

How to Record GIFs from iOS Simulator

Creating GIFs from your iOS Simulator is a great way to showcase features, document animations, or report bugs. Let’s look at the easiest ways to do this. Record a GIF from the iOS Simulator The simplest way to record a video of your app running in the iOS Simulator is using its built-in screen recording feature. Launch your app in the iOS Simulator. With the Simulator window active, go to File > Record Screen in the macOS menu bar, or press the shortcut Cmd + R, or hold Option and click on the record button in the Simulator’s title bar. A recording indicator (a small circle) will appear in the Simulator’s title bar. Perform the actions you want to capture. To stop, click the recording indicator again, or press Cmd + R. A thumbnail of your recording will appear. Right-click that recording then select Save as Animated Gif. ...

Swift Optionals

When you start learning Swift, one of the concepts you’ll encounter early on is optionals. Optionals are a powerful feature of Swift that help you write safer and more robust code by explicitly handling the possibility that a value might be missing. This post will explain what optionals are, why they are important, and how to work with them. What is an Optional? In Swift, an optional is a type that can hold either a value or no value at all. When an optional doesn’t have a value, it’s said to be nil. Think of it like a box: the box might contain an item, or it might be empty. ...

Swift Closures

Closures are self-contained pieces of code that you can store and pass around your codebase. Think of them as unnamed functions that can capture and store references to any constants and variables from the context in which they’re defined. If you’ve used functions in Swift, then you’ll soon grasp closures as they are actually a special case of closures. Closures are used very often in iOS development. You’ll see them in: completion handlers, animations, collection methods like map and filter, and SwiftUI view builders. Let’s look at them in more detail. ...

SwiftUI Text View

The role of Text view in SwiftUI is to display text (funny that). It can support simple labels, rich content or dynamic text. It is the SwiftUI equivalent to UILabel. Let’s get look at it in more detail. Creating Basic Text Simply pass a string to the Text initialiser: Text("Hello, SwiftUI!") You can also use string interpolation to create dynamic text: let userName = "Mike" Text("Welcome back, \(userName)!") ...