MasterOnce
HomeBlogHow-To

How-To Library

Copy, paste, and ship

Practical Swift guides with ready-to-run code.

3 min readMar 15, 2026

How to Format Numbers

Use NumberFormatter for readable output.

Swift
3 min readMar 14, 2026

How to Use NavigationStack

Build navigation using the modern API.

Swift
3 min readMar 13, 2026

How to Build a List in SwiftUI

Render a list from an array.

Swift
3 min readMar 12, 2026

How to Use ObservableObject

Share state across multiple views.

Swift
3 min readMar 11, 2026

How to Use @Binding

Pass state down and edits back up.

Swift
3 min readMar 10, 2026

How to Use @State in SwiftUI

Store local view state with @State.

Swift
3 min readMar 9, 2026

How to Write a Simple Unit Test

Use XCTest to verify behavior.

Swift
3 min readMar 8, 2026

How to Match with Regex

Use Swift Regex for pattern matching.

Swift
3 min readMar 7, 2026

How to Use Result

Represent success or failure explicitly.

Swift
3 min readMar 6, 2026

How to Create a Property Wrapper

Wrap common logic in a reusable property wrapper.

Swift
3 min readMar 5, 2026

How to Use a Timer

Run repeated work on a schedule.

Swift
3 min readMar 4, 2026

How to Use NotificationCenter

Broadcast and listen for events in your app.

Swift
3 min readMar 3, 2026

How to Read and Write Files

Write a text file to the documents directory.

Swift
3 min readMar 2, 2026

How to Save Data with UserDefaults

Persist small settings with UserDefaults.

Swift
3 min readMar 1, 2026

How to Use @MainActor

Ensure UI updates happen on the main thread.

Swift
3 min readFeb 28, 2026

How to Use Actors

Protect mutable state in concurrent code.

Swift
3 min readFeb 27, 2026

How to Use async let

Run async tasks in parallel.

Swift
3 min readFeb 26, 2026

How to Use Async/Await

Write async code that reads like sync code.

Swift
3 min readFeb 25, 2026

How to Make a POST Request with URLSession

Send JSON data in a POST request.

Swift
3 min readFeb 24, 2026

How to Make a GET Request with URLSession

Fetch data from a URL in a few lines.

Swift
3 min readFeb 23, 2026

How to Decode JSON with Codable

Parse JSON into Swift types.

Swift
3 min readFeb 22, 2026

How to Format Dates

Use DateFormatter for readable dates.

Swift
3 min readFeb 21, 2026

How to Sort Arrays

Sort arrays using sort and sorted.

Swift
3 min readFeb 20, 2026

How to Use map, filter, reduce

Transform collections with functional helpers.

Swift
3 min readFeb 19, 2026

How to Use Trailing Closures

Write cleaner call sites with trailing closure syntax.

Swift
3 min readFeb 18, 2026

How to Write Closures

Use closures for inline, reusable behavior.

Swift
3 min readFeb 17, 2026

How to Use typealias

Improve readability by renaming complex types.

Swift
3 min readFeb 16, 2026

How to Write a Generic Function

Make functions reusable across types.

Swift
3 min readFeb 15, 2026

How to Use defer in Swift

Guarantee cleanup work at the end of a scope.

Swift
3 min readFeb 14, 2026

How to Create Custom Errors

Define clear error types for your domain.

Swift
3 min readFeb 13, 2026

How to Handle Errors with do/try/catch

Handle throwing functions safely.

Swift
3 min readFeb 12, 2026

How to Use Access Control

Restrict visibility with public, internal, and private.

Swift
3 min readFeb 11, 2026

How to Use Static Properties

Store shared values on the type itself.

Swift
3 min readFeb 10, 2026

How to Use Lazy Properties

Delay expensive setup until first use.

Swift
3 min readFeb 9, 2026

How to Use Property Observers

React to changes with willSet and didSet.

Swift
3 min readFeb 8, 2026

How to Use Computed Properties

Derive values without storing them.

Swift
3 min readFeb 7, 2026

How to Add Methods with Extensions

Extend existing types without subclassing.

Swift
3 min readFeb 6, 2026

How to Add Default Protocol Implementations

Provide shared behavior with protocol extensions.

Swift
3 min readFeb 5, 2026

How to Define a Protocol

Use protocols to define shared requirements.

Swift
3 min readFeb 4, 2026

How to Use Class Inheritance

Reuse base behavior with subclassing.

Swift
3 min readFeb 3, 2026

How to Create a Class

Use classes for reference semantics and shared state.

Swift
3 min readFeb 2, 2026

How to Create a Struct

Use structs for lightweight data models.

Swift
3 min readFeb 1, 2026

How to Define an Enum

Group related values with enums.

Swift
3 min readJan 31, 2026

How to Use Nil Coalescing

Provide a default value when optional is nil.

Swift
3 min readJan 30, 2026

How to Use guard let for Early Exit

Keep functions readable by handling failures up front.

Swift
3 min readJan 29, 2026

How to Use Optionals Safely

Handle missing values without crashes.

Swift
3 min readJan 28, 2026

How to Use Sets

Track unique values with fast membership checks.

Swift
3 min readJan 27, 2026

How to Use Dictionaries

Store key-value data with fast lookups.

Swift
3 min readJan 26, 2026

How to Work with Arrays

Create, update, and iterate arrays safely.

Swift
3 min readJan 25, 2026

How to Use Tuples for Quick Grouping

Return or group small bits of data without a custom type.

Swift
3 min readJan 24, 2026

How to Use Default Parameters

Provide sensible defaults to keep call sites clean.

Swift
3 min readJan 23, 2026

How to Define and Call Functions

Extract logic into reusable functions.

Swift
3 min readJan 22, 2026

How to Use a While Loop

Repeat work while a condition remains true.

Swift
3 min readJan 21, 2026

How to Write a For-In Loop

Loop through sequences using for-in.

Swift
3 min readJan 20, 2026

How to Use Switch in Swift

Match values safely with exhaustive switch cases.

Swift
3 min readJan 19, 2026

How to Write If-Else Logic

Branch behavior with clear, readable conditions.

Swift
3 min readJan 18, 2026

How to Read User Input from the Console

Use readLine to capture simple input in CLI tools.

Swift
3 min readJan 17, 2026

How to Use String Interpolation

Build readable strings with interpolation and formatting.

Swift
3 min readJan 16, 2026

How to Use Variables and Constants

Prefer constants with let and fall back to var only when needed.

Swift
3 min readJan 15, 2026

How to Print Output in Swift

Use print and debugPrint to inspect values quickly.

Swift