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-isolated state
Project style 35 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

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.

Class and protocol design

FlightPlanner/FlightPlannerApp.swift:12 — representative type boundary

struct FlightPlannerApp: App {
    var body: some Scene {
        WindowGroup {
            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 {
        // ...
    }

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-isolated state FlightPlanner/Models/AirportData.swift:31 Actor annotations make the concurrency ownership boundary explicit.

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 FlightPlannerApp
FlightPlanner/Models/FlightLegGenerator.swift FlightLegGenerator
FlightPlanner/Models/FlightSegmentGenerator.swift FlightSegmentGenerator
FlightPlanner/Views/BookingForm/BookingFormAirportDetails.swift BookingFormAirportDetails, OriginAirportButton, DestinationAirportButton, JourneyIcon, BookingFormAirportDetails_Previews
FlightPlanner/Views/ContentView.swift ContentView, ContentView_Previews
FlightPlanner/Models/Airport.swift Airport, CodingKeys, SeededRandomNumberGenerator
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/AirportData.swift AirportData, Store