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)!") ...

Swift Functions

Functions are reusable blocks of code that perform specific tasks. They’re fundamental to organising your code, avoiding repetition, and making your programs easier to understand and maintain. Think of a function as a mini-program that takes some input, does something useful with it, and optionally gives you back a result. In Swift, functions are first-class citizens—you can pass them around, store them in variables, and use them just like any other data type. ...