Start a project

Swift A–Z · 15 terms

Swift references M–R

Explore an M-R directory of essential Swift terms. Each entry delivers clear definitions, practical code examples, and usage tips tailored for iOS and watchOS developers. This reference empowers you to master Swift’s nuances quickly, with balanced coverage across letters for consistent depth.

M

Map

Map transforms each element in a collection using a closure.

let numbers = [1, 2, 3]
let doubled = numbers.map { $0 * 2 }

Usage tip: Process data for SwiftUI views in iOS; efficient transformations for watchOS arrays.

Modifier

Modifier customizes SwiftUI views.

Text("Hello").font(.title)

Usage tip: Chain for styling in iOS interfaces; optimize modifiers on watchOS to avoid redraws.

N

NavigationStack manages a stack of views for navigation in SwiftUI.

NavigationStack {
    NavigationLink("Go", destination: Text("Destination"))
}

Usage tip: Build hierarchical UIs in iOS apps; limited depth on watchOS for usability.

Nil

Nil represents the absence of a value for optionals.

let optional: String? = nil

Usage tip: Handle missing data in iOS models; check for nil in watchOS to prevent errors.

NotificationCenter

NotificationCenter broadcasts information within an app.

NotificationCenter.default.post(name: .init("event"), object: nil)

Usage tip: Sync state across iOS views; use for watchOS complications updates.

O

Observable

Observable is a macro for types that notify changes to observers.

@Observable
class ViewModel {
    var count = 0
}

Usage tip: Reactive state in SwiftUI for iOS; efficient updates on watchOS.

Optional

Optional is a type that can hold a value or nil.

var maybe: Int? = 42

Usage tip: Safe handling in iOS APIs; unwrap carefully on watchOS.

Override

Override reimplements a superclass method.

class Base { func method() {} }
class Derived: Base { override func method() {} }

Usage tip: Customize behavior in iOS subclasses; rarely needed on watchOS.

P

Protocol

Protocol defines a blueprint of methods and properties.

protocol Identifiable {
    var id: Int { get }
}

Usage tip: Conform types for SwiftUI in iOS; protocols for watchOS extensions.

Property Wrapper

Property wrapper adds behavior to properties.

@propertyWrapper struct Clamped<T: Comparable> {
    var wrappedValue: T
}

Usage tip: State management in iOS views; custom wrappers for watchOS.

Published

Published is a property wrapper that publishes changes.

class ViewModel: ObservableObject {
    @Published var count = 0
}

Usage tip: Bind to SwiftUI in iOS; reactive UI on watchOS.

Q

Queue

Queue is a data structure for FIFO operations, often using DispatchQueue.

let queue = DispatchQueue(label: "com.example.queue")
queue.async { print("Task") }

Usage tip: Background work in iOS; concurrent tasks on watchOS.

R

Repeat-While

Repeat-while executes a loop at least once, checking the condition after.

repeat {
    // code
} while condition

Usage tip: Guaranteed execution in iOS loops; useful for watchOS retries.

Return

Return exits a function and provides a value.

func sum(a: Int, b: Int) -> Int {
    return a + b
}

Usage tip: Function results in iOS logic; clear returns on watchOS.

Reduce

Reduce combines collection elements into a single value.

let sum = [1, 2, 3].reduce(0, +)

Usage tip: Aggregate data for iOS stats; computations on watchOS.

All letters · The full guide · Articles