G
Generic
Generics enable writing flexible, reusable functions and types that work with any type, subject to requirements.
func swap<T>(_ a: inout T, _ b: inout T) {
let temp = a
a = b
b = temp
}Usage tip: Use generics in SwiftUI views for type-safe reusable components in iOS apps; on watchOS, for efficient data models that adapt to different types.
GeometryReader
GeometryReader is a SwiftUI container view that provides its content with the geometry of its parent.
GeometryReader { geometry in
Rectangle().frame(width: geometry.size.width / 2)
}Usage tip: Position subviews dynamically in iOS layouts; on watchOS, use sparingly to avoid performance issues on smaller screens.
Group
Group is a SwiftUI view that groups child views without affecting layout.
Group {
Text("Hello")
Text("World")
}Usage tip: Organize complex SwiftUI hierarchies in iOS; helpful for conditional content on watchOS without layout changes.
Guard
Guard is a statement for early exits if conditions aren't met, improving code readability.
guard let value = optional else { return }
print(value)Usage tip: Validate inputs in iOS functions; essential for safe unwrapping in watchOS data processing to prevent crashes.
H
Hashable
Hashable is a protocol for types that can be hashed into a Hasher, required for use in sets and dictionaries.
struct Point: Hashable {
let x: Int
let y: Int
}Usage tip: Conform models to Hashable for SwiftUI ForEach ids in iOS lists; on watchOS, for unique item tracking in complications.
HStack
HStack is a SwiftUI view that arranges its children in a horizontal line.
HStack {
Text("Left")
Text("Right")
}Usage tip: Build toolbars or rows in iOS interfaces; on watchOS, ideal for side-by-side elements in limited space.
I
If
If is a conditional statement that executes code based on a boolean condition.
if condition {
print("True")
} else {
print("False")
}Usage tip: Control flow in SwiftUI view builders for iOS; simple conditions for watchOS state changes.
Import
Import brings in declarations from another module.
import SwiftUIUsage tip: Access frameworks like UIKit in iOS projects; selective imports for watchOS to minimize bundle size.
Init
Init is an initializer that sets up a new instance of a type.
struct Person {
var name: String
init(name: String) {
self.name = name
}
}Usage tip: Customize object creation in iOS models; required inits ensure safety on watchOS.
Inout
Inout allows a function to modify a parameter's value outside its scope.
func increment(_ value: inout Int) {
value += 1
}Usage tip: Mutate external state in iOS closures; use cautiously on watchOS for performance.
Int
Int is a signed integer type.
let number: Int = 42Usage tip: Store counts in SwiftUI state for iOS; arithmetic in watchOS fitness trackers.
Is
Is checks if an instance is of a certain type.
if value is String {
print("It's a string")
}Usage tip: Type checking in iOS heterogeneous data; dynamic casting on watchOS.
J
JSONDecoder
JSONDecoder decodes JSON data into Codable types.
let decoder = JSONDecoder()
let user = try decoder.decode(User.self, from: data)Usage tip: Parse API responses in iOS networking; lightweight decoding for watchOS syncs.
JSONEncoder
JSONEncoder encodes Codable types into JSON data.
let encoder = JSONEncoder()
let data = try encoder.encode(user)Usage tip: Serialize data for iOS storage; encode for watchOS cloud uploads.
K
KeyPath
KeyPath is a type-safe reference to a property.
let nameKey = \Person.name
let name = person[keyPath: nameKey]Usage tip: Dynamic property access in iOS sorting; bindings in watchOS observables.
L
Label
Label is a SwiftUI view that combines an icon and text.
Label("Settings", systemImage: "gear")Usage tip: Menu items in iOS sidebars; compact labels for watchOS interfaces.
Lazy
Lazy is a property wrapper that delays initialization until first access.
class DataLoader {
@Lazy var data: Data = loadData()
}Usage tip: Optimize startup in iOS apps; defer heavy loads on watchOS for battery life.
Let
Let declares a constant value.
let constant = 10Usage tip: Immutable state in SwiftUI views for iOS; constants for watchOS configurations.
List
List is a SwiftUI view that displays a scrollable list of rows.
List {
Text("Item 1")
Text("Item 2")
}Usage tip: Display data tables in iOS; swipe actions on watchOS for interactive lists.
Loop
Loops repeat code execution, such as for-in or while.
while condition {
// code
}Usage tip: Process arrays in iOS background; efficient loops for watchOS real-time data.