Sample CodeiOS, iPadOSReviewed 2026-07-21View on Apple Developer

Fetching weather forecasts with WeatherKit

At a glance

Item Summary
Purpose Request and display weather data for destination airports in a flight-planning app.
App architecture A Swift sample with the source-visible chain FlightPlannerAppContentViewStoreFlightLegGeneratorWeatherKit APIs.
Main patterns Central store, Binding-based state propagation, Publisher-backed observable state, Actor isolation
Project style 35 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: @MainActor, async declaration or closure, actor, Sendable or @Sendable, Task.detached; none alone proves a background thread.
State/event model Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, Foundation, WeatherKit, os, CoreLocation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── FlightPlanner/
    ├── FlightPlannerApp.swift
    ├── Models/
    │   ├── FlightLegGenerator.swift
    │   ├── FlightSegmentGenerator.swift
    │   ├── Airport.swift
    │   ├── AirportData.swift
    │   ├── FlightData.swift
    │   └── FlightForecastInfo.swift
    └── Views/
        ├── BookingForm/
        │   ├── BookingFormAirportDetails.swift
        │   └── BookingFormDateDetails.swift
        ├── ContentView.swift
        ├── FlightItineraryList/
        │   └── FlightLegRowHeader.swift
        └── FlightLegDetail/
            └── FlightLegDetailWeatherGrid.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Swift.
  • The verified tree contains 4 project/configuration file(s) and 55 source declaration(s).

Overall architecture

Reference code

FlightPlanner/FlightPlannerApp.swift:11 — architecture anchor

@main
struct FlightPlannerApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into WeatherKit.

Ownership and state

Ownership evidence

FlightPlanner/Views/BookingForm/BookingFormAirportDetails.swift:12 — stored dependency or nearest verified ownership anchor

struct BookingFormAirportDetails: View {
    var airports: [Airport]
    // ...
}
Owner Object or state Relationship Mutation authority
BookingFormAirportDetails Array (airports) owns value state App/module collaborators
BookingFormAirportDetails Airport (origin) stores or receives App/module collaborators
BookingFormAirportDetails Airport (destination) stores or receives App/module collaborators
BookingFormAirportDetails FlightJourney (journey) stores or receives App/module collaborators

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

Concern Source mechanism Verified placement or handoff Evidence
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. FlightPlanner/Models/AirportData.swift:11
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. FlightPlanner/Models/AirportData.swift:25
Actor isolation actor The cited type is actor-isolated; this does not select a background thread. FlightPlanner/Models/AirportData.swift:31
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. FlightPlanner/Models/BookingFormInputData.swift:12
Detached task Task.detached The source creates a detached task; no specific operating-system thread is established. FlightPlanner/Models/FlightData.swift:35

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

Reference code

FlightPlanner/Models/AirportData.swift:11 — representative execution boundary

@MainActor
class AirportData: ObservableObject {
    let logger = Logger(subsystem: "com.example.apple-samplecode.FlightPlanner.AirportData", category: "Model")
    // ...
}

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
State propagation ObservableObject ObservableObject supplies an observation contract. FlightPlanner/Models/AirportData.swift:12
State propagation @Published A published property can emit owner-controlled changes. FlightPlanner/Models/AirportData.swift:16
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. FlightPlanner/Views/BookingForm/AirportPicker.swift:19
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. FlightPlanner/FlightPlannerApp.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. FlightPlanner/Models/Airport.swift:8
Source import WeatherKit The cited file imports this module; runtime use and architectural role are not inferred. FlightPlanner/Models/FlightForecastInfo.swift:10
Source import os The cited file imports this module; runtime use and architectural role are not inferred. FlightPlanner/Models/AirportData.swift:9
Source import CoreLocation The cited file imports this module; runtime use and architectural role are not inferred. FlightPlanner/Models/Airport.swift:9

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

FlightPlanner/FlightPlannerApp.swift:12 — representative type boundary

@main
struct FlightPlannerApp: App {
    // ...
            ContentView()
    // ...
}
Type Responsibility Depends on or conforms to
FlightPlannerApp Application entry and top-level composition App
FlightLegGenerator Generates feature data or resources Concrete collaborators/imported frameworks
FlightSegmentGenerator Generates feature data or resources Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
SeededRandomNumberGenerator Generates feature data or resources RandomNumberGenerator
Store Centralized state or persistence access Concrete collaborators/imported frameworks
Store Centralized state or persistence access Concrete collaborators/imported frameworks
BookingFormAirportDetails Represents a feature value or composable behavior View
OriginAirportButton Represents a feature value or composable behavior View
DestinationAirportButton Represents a feature value or composable behavior View

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
randomImageName (FlightPlanner/Models/Airport.swift:56) fileprivate Use is restricted to this source file. Inference: share with same-file helpers or extensions without exposing the symbol module-wide.
airports (FlightPlanner/Models/AirportData.swift:16) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
store (FlightPlanner/Models/AirportData.swift:22) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
load (FlightPlanner/Models/AirportData.swift:38) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.

Reference code

FlightPlanner/Models/Airport.swift:56 — representative boundary

    fileprivate static func randomImageName(for airport: Airport) -> String {
        // ...
        let sum = airport.elevation + airport.latitude + airport.longitude
        // ...
    }

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Application entry and top-level composition FlightPlannerApp The source’s App suffix makes this role explicit.
Generates feature data or resources FlightLegGenerator, FlightSegmentGenerator, SeededRandomNumberGenerator The source’s Generator suffix makes this role explicit.
Centralized state or persistence access Store The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding ContentView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Central store FlightPlanner/Models/AirportData.swift:31 A store-named type centralizes feature state or persistence.
Binding-based state propagation FlightPlanner/Views/BookingForm/AirportPicker.swift:19 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Publisher-backed observable state FlightPlanner/Models/AirportData.swift:16 Published properties notify observers while mutation remains with the state object.
Actor isolation FlightPlanner/Models/AirportData.swift:31 A declared actor creates an explicit isolation boundary; its executor is not described as a background thread.

Naming conventions

  • Types: App: FlightPlannerApp; Generator: FlightLegGenerator, FlightSegmentGenerator, SeededRandomNumberGenerator; Store: Store; View: ContentView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: makeLeg, makeDeparture, makeArrival, segment, onDelete, randomImageName, next, makeBody.
  • Files: FlightPlanner/FlightPlannerApp.swift, FlightPlanner/Models/FlightLegGenerator.swift, FlightPlanner/Models/FlightSegmentGenerator.swift, FlightPlanner/Views/BookingForm/BookingFormAirportDetails.swift, FlightPlanner/Views/ContentView.swift, FlightPlanner/Models/Airport.swift.

Architecture takeaways

  • FlightPlannerApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, WeatherKit, CoreLocation through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
FlightPlanner/FlightPlannerApp.swift Cited implementation, FlightPlannerApp, SwiftUI
FlightPlanner/Views/BookingForm/BookingFormAirportDetails.swift Cited implementation, BookingFormAirportDetails, OriginAirportButton, DestinationAirportButton, JourneyIcon, BookingFormAirportDetails_Previews
FlightPlanner/Models/Airport.swift Cited implementation, Foundation, CoreLocation, Airport, CodingKeys, SeededRandomNumberGenerator
FlightPlanner/Models/AirportData.swift Cited implementation, Store, @MainActor, async declaration or closure, actor, ObservableObject, @Published, os, AirportData
FlightPlanner/Views/BookingForm/AirportPicker.swift Cited implementation, SwiftUI state property wrapper, AirportPicker, Role, AirportPicker_Previews
FlightPlanner/Models/BookingFormInputData.swift Sendable or @Sendable, BookingFormInputData
FlightPlanner/Models/FlightData.swift Task.detached, FlightData, Store
FlightPlanner/Models/FlightForecastInfo.swift WeatherKit, FlightForecastInfo, Temperature
FlightPlanner/Models/FlightLegGenerator.swift FlightLegGenerator
FlightPlanner/Models/FlightSegmentGenerator.swift FlightSegmentGenerator
FlightPlanner/Views/ContentView.swift ContentView, ContentView_Previews
FlightPlanner/Views/BookingForm/BookingFormDateDetails.swift BookingFormDateDetails, DepartureDatePicker, ReturnDatePicker, BookingFormDateDetails_Previews
FlightPlanner/Views/FlightItineraryList/FlightLegRowHeader.swift FlightLegRowHeader, Icon, AlignmentLabelStyle, FlightLegRowHeader_Previews
FlightPlanner/Views/FlightLegDetail/FlightLegDetailWeatherGrid.swift FlightLegDetailWeatherGrid, HeaderGridRow, ForecastGridRow, FlightLegDetailWeatherGrid_Previews
FlightPlanner/Models/FlightSegment.swift FlightSegment, Color
FlightPlanner/Views/BookingForm/BookingFormPassengerDetails.swift BookingFormPassengerDetails, PassengersStepper, BookingFormPassengerDetails_Previews