Timeline

#swift

8 entries following this thread through the timeline.

#shipped Nicholas Clooney

skill: Engineering standards for every app

I added engineering-standards to my skills in 8329df9. I want every app I build to start from the same foundation: simple objects, strong single responsibility, strong boundaries, full dependency injection, and state and logic you can test. Writing it down once means agents build to that standard by default, instead of me re-explaining it on every project.

  • Five core rules up front. SKILL.md holds them, each a principle with its Swift form; 17 more rules sit in three reference files (structure and dependencies, screen state and presentation, tests) loaded only when needed.
  • Fake the world, keep my layers real. Tests replace only the outside world; canned values at a unit's own injected functions are fine, recording mocks are out.
  • Precise values stay precise. Money and similar values use a decimal type parsed from strings.
		
  1. ---
  2. name: engineering-standards
  3. description: Build and review app code to a fixed set of engineering standards (simple objects, single responsibility, strong boundaries, full dependency injection, testable state and logic), each stated as a principle with its Swift or SwiftUI form. Use when designing or reviewing app architecture, wiring dependency injection, writing view models or view states, mapping network responses and errors into domain types, applying code layout conventions, or when the user says "our standards" or "to our engineering standards".
  4. ---
  5. # Engineering standards
  6. Principle first, then the Swift form as one example; in another language, use its plainest idiom for the same rule. Test shape, doubles, factories and fixtures are in the `behavior-tests` skill; the rules in the tests reference add only what that skill leaves open.
  7. ## Core
  8. 1. **Simple objects.** Values and functions before classes and interfaces. Domain and view-state types are immutable values; computation is pure functions grouped by topic. A class only where mutable, observed state lives (the view model); an interface only for a real boundary, never one interface and one mock per dependency. Swift: `let`-only structs and enums, `static func`s on a `nonisolated enum`, one `@Observable` class per screen.
  9. 2. **Strong single responsibility.** One type, one job, named after the job. Networking alone is four types: configuration (base URL, version), endpoints (paths), client (fetch and decode), mapper (wire type to domain). The reverse holds too: actions that share one piece of state stay in one type instead of being split to shorten it.
  10. 3. **Strong boundaries.** Each layer speaks only its own types, and raw data stops at the edge. A weather DTO holds the server's strings; the repository maps it to a `Forecast` with typed temperatures; every failure becomes the layer's own error before it crosses. Callers consume capabilities (`fetchForecast`), never construct lower layers. A view sees view states, never a DTO or the client.
  11. 4. **Full dependency injection.** Every side effect (network, stored data, a delay's length) is passed in at construction with no default, so a caller can't forget it and a test can't be fooled by a built-in. One composition root: the entry point reads the configuration switches and builds the live wiring as locals in one function; preview or demo wiring is a second set that doesn't ship. Nothing below the root reads a global. Time and delays are injected only when a test needs to control them; a presentation delay doesn't earn a clock. Swift: `@Sendable` closures in `init`; `Dependencies+Live.swift`, and `Dependencies+Preview.swift` behind `#if DEBUG`; no `URLSession.shared` outside the root.
  12. 5. **Testable state and logic.** State is a value you can assert on: one state enum with payloads, readable by all and written only by its owner's actions. Logic is a pure function whose inputs (locale, units, the loaded data) are parameters, so a test needs no environment. Tests drive the real types through the user's flow and fake only the outermost boundary. Swift: `enum State: Equatable`, `private(set) var state`, `#expect(viewModel.state == .loaded(expected))`.
  13. ## Reference
  14. - Read [structure.md](references/structure.md) when separating view models from view states, wiring dependencies, defining configuration, concurrency, validation and error boundaries, choosing request serialization or boundary payloads, naming functions and their argument labels, grouping members and function stages, or choosing enum projections versus behavioural pattern matching.
  15. - Read [layout.md](references/layout.md) when formatting multiline conditions, arguments, parameters or nested calls.
  16. - Read [screen-state.md](references/screen-state.md) when deriving screen state, formatting values, guarding async actions, extracting components or documenting escape hatches.
  17. - Read [tests.md](references/tests.md) when choosing test boundaries, recording fixture provenance, covering screen states offline or verifying request wire output.
  18. ## Done
  19. Each changed type has one job and a name that says it, every side effect enters through its initialiser, every new boundary has its own types and error, and each behaviour has a test that reads as the user's flow with only the world faked.

#published Nicholas Clooney

blog: A refresher on SwiftUI state management, async/await, and common patterns

I published A refresher on SwiftUI state management, async/await, and common patterns, turning a private set of interview-prep notes into a working refresher for the SwiftUI you actually meet in real codebases. It covers the pre-iOS 17 property wrappers next to their @Observable equivalents, async/await as the default for data loading, and the everyday shapes for networking, navigation, and error handling. The next entry in the Swift series, written for the version of me that has been away from SwiftUI long enough to want one page that catches him back up.

#shipped Nicholas Clooney

bite: SwiftUI components library demos

I shipped d60e0e1 in SwiftyBites with a new SwiftUIComponentsLibrary area for pickers, menus, search scopes and tokens, and width-showcase layouts.

The useful part is not just the snippets themselves, but that AI agents researched the best practices, produced the example code, organized the project, and left me with a runnable playground where I can compare equal-width stacks, GeometryReader, PreferenceKey, and some surprisingly similar results against my actual needs.

#published Nicholas Clooney

blog: The Confident Lie: What AI Got Wrong About @ViewBuilder

I published The Confident Lie: What AI Got Wrong About @ViewBuilder, a SwiftUI debugging note that came out of the ProjectSpire card view work. It captures a small but useful lesson: body gets @ViewBuilder from the View protocol, but a custom computed some View property needs the annotation explicitly if I want an if without an else. The compiler was right, the AI was overconfident, and now the mistake is written down somewhere I can find again.

#published Nicholas Clooney

blog: Three ways to pass an @Observable object in SwiftUI

I published Three ways to pass an @Observable object in SwiftUI, a short SwiftUI reference for choosing between environment injection, direct initializer passing, and @Binding. It keeps the distinction focused on ownership and coupling: whole-object reference sharing when the child is allowed to know the model, or a projected binding when the child should only see one value.

#shipped Nicholas Clooney

bite: Async debounce demo in SwiftyBites

I pushed 1263f2d to SwiftyBites as a Friday-night AsyncDebounceDemo for playing with Swift's async and sync edges. The demo compares a view-owned async .task flow with a synchronous button action that cancels and restarts a stored Task, which makes the debounce mechanics feel a lot more concrete than just reading the pattern.

#published Nicholas Clooney

blog: SwiftUI .task(id:) debounce update

I updated SwiftUI in the Wild: Memory, Concurrency, and the Gaps in the Docs with a clearer explanation of using .task(id:) for debounced work. The change moves that pattern into the debounce section, where SwiftUI's automatic cancellation model fits naturally, and keeps the button-action section focused on manual task ownership tradeoffs.

#published Nicholas Clooney

blog: SwiftUI in the Wild: Memory, Concurrency, and the Gaps in the Docs

I published SwiftUI in the Wild: Memory, Concurrency, and the Gaps in the Docs, a field guide to the parts of modern SwiftUI + concurrency that look clean in isolation but get messy in real apps. The post covers @State + @Observable lifetime bugs, debouncing with async/await, task ownership in views and buttons, closure capture cycles, and why @Observable and actor pull in different architectural directions.