tezvyn:

iOS & Swift

SwiftUI, UIKit, Xcode, Swift language, Apple platforms

309 bites

More in iOS & Swift — page 8

iOS & Swift2 min read

withCheckedThrowingContinuation: Bridge Callbacks to Async/Await

withCheckedThrowingContinuation bridges legacy completion-handler APIs into async/await. Wrap one-shot callback-based work so callers use try await instead of nested blocks. The footgun is resuming twice or never, which checked runtimes catch in debug builds.

iOS & Swift2 min read

Unwind Segues: Jump Back in the Stack

An unwind segue jumps from a deep screen to an earlier view controller without manual popping. Use it after multi-step flows to return to a root screen. If multiple screens share the same action, UIKit picks the nearest one and silently routes users wrong.

iOS & Swift2 min read

Map Data to Views Using navigationDestination

navigationDestination turns NavigationStack into a router: register a view per data type, then push raw values. It frees view models from creating views. Using it outside NavigationStack or mixing it with old NavigationLink destinations silently breaks…

iOS & Swift2 min read

SwiftUI Sheets: State-Driven Modal Overlays

A SwiftUI sheet is a temporary, state-bound overlay that slides over your current view. Use it for focused tasks like composing a message or picking a date. State and environment values do not automatically propagate into its isolated view hierarchy.

iOS & Swift2 min read

TCA: Unidirectional State for SwiftUI

TCA is a strict pipeline for SwiftUI: state and actions enter a pure reducer, emitting new state and effects. Use it when complex flows need reproducible tests without launching the app.

iOS & Swift2 min read

Build Custom Instruments with os_signpost

os_signpost turns code intervals into Instruments graphs by pairing begin-end markers with a visualization package. Use it to correlate app work like model hydration with system CPU and memory metrics. Unmatched begin-end calls break tracks and ruin the view.

iOS & Swift2 min read

Swift Existential Types: The Polymorphism Box

An existential type is a boxed protocol: you see the interface, not the concrete type inside. Use it to store mixed concrete types behind one protocol, like [any Logger]. Prefer generics; existentials hide types and add dynamic dispatch overhead.

iOS & Swift2 min read

Protocol-Oriented Programming in Swift

Protocol-oriented programming swaps inheritance for composable capabilities via protocol extensions. Use it to share behavior across structs without forcing a superclass. The footgun is protocol bloat: indirection without reuse is bureaucracy.

iOS & Swift2 min read

Swift Properties: Accessors in Disguise

A Swift property runs code on every read or write. Use stored properties for state, computed properties for derived values, and observers for side effects. The footgun is heavy work in a computed getter, turning innocent dot syntax into a performance trap.

iOS & Swift2 min read

Swift Closures: Functions with a Memory

A closure is a function carrying luggage: it captures surrounding variables and remembers them later. Use them in SwiftUI actions, async completions, and array transforms. Beware a strong reference cycle from capturing self without a capture list.

iOS & Swift2 min read

Swift Collections: Array, Set, Dictionary

Swift's three collections are different access patterns, not just different APIs. Arrays keep order, Sets enforce uniqueness, and Dictionaries map keys to values. Picking an Array for uniqueness checks turns membership from O(1) into O(n) scans.

iOS & Swift2 min read

Swift Basic Types: Value Semantics by Default

Swift's basic types are value type structs, so assignment copies, not shares, a reference. You feel this when passing Strings into functions or choosing Int over Double. The footgun is treating them as free to copy; large values cost memory and speed.

iOS & Swift2 min read

Apple's Natural Language Framework

Apple's Natural Language Framework turns raw strings into structured meaning on-device without network calls. Tokenize queries or extract entities from user text locally. It is not infallible; heavy synchronous tagging on the main thread freezes your UI.

iOS & Swift2 min read

UserNotifications Framework: iOS Alert Gatekeeper

UserNotifications is the gatekeeper between your app and the lock screen. You use it to request permission and schedule local or push alerts on iOS. Send a notification before authorization and the system silently drops it.

iOS & Swift2 min read

Result Builders: Declarative Swift DSLs

Result builders teach the compiler to fold expressions into one combined value, enabling declarative DSLs. SwiftUI relies on them to compose stacked views. Type errors surface on compiler-generated boilerplate instead of your original code.

iOS & Swift2 min read

Swift Enums: Type-Safe Choice Modeling

A Swift enum is a closed menu of possibilities the compiler tracks exhaustively. Use it to replace string constants or model a network result state. Adding a case without updating every switch breaks compile-time safety if you rely on a default clause.

iOS & Swift2 min read

The Package.swift Manifest File

Think of Package.swift as a recipe for your code, telling the Swift Package Manager (SPM) what to build, what it needs, and where it can run. You use it to define libraries, list dependencies, and set minimum OS versions.

iOS & Swift2 min read

Swift Property Wrappers: Reusable Logic for Properties

A Swift Property Wrapper is a template for a property's get/set logic, letting you reuse behaviors like data validation without boilerplate. It powers SwiftUI's @State and is great for managing UserDefaults.

Refining Objective-C APIs for Swift with NS_SWIFT_NAME
iOS & Swift88 sec read

Refining Objective-C APIs for Swift with NS_SWIFT_NAME

NS_SWIFT_NAME gives Objective-C code a Swifty alias without changing the original API. Use it to modernize legacy frameworks by removing prefixes for Swift consumption.

Optimizing iOS App Launch Time
iOS & Swift2 min read

Optimizing iOS App Launch Time

An app launch is a race against the system's watchdog timer. The OS loads your app in two phases: pre-main and main. Optimizing both is key. The biggest footgun is ignoring the pre-main phase, where bloated dynamic libraries can kill performance.