Adding intelligent app features with generative models
At a glance
| Item | Summary |
|---|---|
| Purpose | Build robust apps with guided generation and tool calling by adopting the Foundation Models framework. |
| App architecture | A Swift sample with the source-visible chain FoundationModelsTripPlannerApp → LandmarksView → FoundationModels APIs. |
| Main patterns | No named application pattern supported by the extracted structure |
| Project style | 22 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, async declaration or closure, Task, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, FoundationModels, MapKit, WeatherKit, CoreLocation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── FoundationModelsTripPlanner/
└── FoundationModelsTripPlanner/
├── FoundationModelsTripPlannerApp.swift
├── Views/
│ ├── Itinerary/
│ │ ├── Effects.swift
│ │ ├── ItineraryView.swift
│ │ ├── LandmarkTripView.swift
│ │ ├── LandmarkDescriptionView.swift
│ │ ├── ItineraryPlanningView.swift
│ │ ├── MessageView.swift
│ │ └── TripPlanningView.swift
│ └── Landmarks/
│ ├── LandmarkDetailMapView.swift
│ └── LandmarkFeaturedItemView.swift
├── Model/
│ └── Itinerary/
│ └── Itinerary.swift
└── Utils.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 5 project/configuration file(s) and 42 source declaration(s).
Overall architecture
flowchart LR
N1["FoundationModelsTripPlannerApp"]
N2["LandmarksView"]
N3["FoundationModels APIs"]
N1 --> N2
N2 --> N3
Reference code
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:10 — architecture anchor
@main
struct FoundationModelsTripPlannerApp: App {
private var modelData = ModelData.shared
var body: some Scene {
WindowGroup {
LandmarksView()
.environment(modelData)
}
}
}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 Foundation Models.
Ownership and state
classDiagram
HeaderStyle o-- Landmark : landmark
ActivityIcon *-- String : symbolName
ActivityIcon *-- CGFloat : iconSize
ItineraryView o-- Landmark : landmark
Ownership evidence
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/Effects.swift:11 — stored dependency or nearest verified ownership anchor
struct HeaderStyle: ViewModifier {
let landmark: Landmark
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
HeaderStyle |
Landmark (landmark) |
stores or receives | Initialized by the owner; the binding is immutable |
ActivityIcon |
String (symbolName) |
owns value state | Initialized by the owner; the binding is immutable |
ActivityIcon |
CGFloat (iconSize) |
owns value state | App/module collaborators |
ItineraryView |
Landmark (landmark) |
stores or receives | Initialized by the owner; the binding is immutable |
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. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:18 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:48 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/LocationLookup.swift:16 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkTripView.swift:66 |
@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
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:18 — representative execution boundary
@Observable
final class FindPointsOfInterestTool: Tool {
// ...
@MainActor var lookupHistory: [Lookup] = []
// ...
}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 | @Observable |
Observation macro publishes source-visible changes. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:11 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/Effects.swift:23 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:8 |
| Source import | FoundationModels |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:8 |
| Source import | MapKit |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Landmark.swift:9 |
| Source import | WeatherKit |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/LocationLookup.swift:8 |
| Source import | CoreLocation |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Landmark.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/Itinerary.swift:8 |
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
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:11 — representative type boundary
@main
struct FoundationModelsTripPlannerApp: App {
private var modelData = ModelData.shared
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
FoundationModelsTripPlannerApp |
Application entry and top-level composition | App |
ItineraryView |
User-interface presentation and input forwarding | View |
DayView |
User-interface presentation and input forwarding | View |
LandmarkTripView |
User-interface presentation and input forwarding | View |
LandmarkDescriptionView |
User-interface presentation and input forwarding | View |
ItineraryPlanningView |
User-interface presentation and input forwarding | View |
MessageView |
User-interface presentation and input forwarding | View |
TripPlanningView |
User-interface presentation and input forwarding | View |
LandmarkDetailMapView |
User-interface presentation and input forwarding | View |
LandmarkFeaturedItemView |
User-interface presentation and input forwarding | 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 |
|---|---|---|---|
modelData (FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:12) |
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. |
mapItems (FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:55) |
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. |
itinerary (FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/ItineraryPlanner.swift:14) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
pointOfInterestTool (FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/ItineraryPlanner.swift:15) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
Reference code
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:12 — representative boundary
@main
struct FoundationModelsTripPlannerApp: App {
private var modelData = ModelData.shared
// ...
}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 | FoundationModelsTripPlannerApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | DayView, ItineraryPlanningView, ItineraryView, LandmarkDescriptionView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| No named application pattern | FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:10 |
The verified source directly composes concrete framework types; this document avoids forcing a pattern name. |
Naming conventions
- Types: App: FoundationModelsTripPlannerApp; View: DayView, ItineraryPlanningView, ItineraryView, LandmarkDescriptionView, LandmarkDetailMapView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
body,rationaleStyle,itineraryStyle,card,tagStyle,blurredBackground,headerStyle,requestItinerary. - Files:
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift,FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/ItineraryView.swift,FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkTripView.swift,FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkDescriptionView.swift,FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/Itinerary.swift,FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/ItineraryPlanningView.swift.
Architecture takeaways
FoundationModelsTripPlannerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, FoundationModels, MapKit, WeatherKit 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 |
|---|---|
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift |
Cited implementation, FoundationModelsTripPlannerApp, SwiftUI |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/Effects.swift |
Cited implementation, SwiftUI state property wrapper, HeaderStyle, CardModifier, TagStyleModifier, RationaleModifier, ItineraryModifier, BlurredBackgroundModifier, ActivityIcon |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift |
Cited implementation, @MainActor, async declaration or closure, @Observable, FoundationModels, FindPointsOfInterestTool, Category, Arguments |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/ItineraryPlanner.swift |
Cited implementation, ItineraryPlanner |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/LocationLookup.swift |
Task, WeatherKit, LocationLookup |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkTripView.swift |
Task closure isolated to MainActor, LandmarkTripView, ItineraryButton, ItineraryHeader |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Landmark.swift |
MapKit, CoreLocation, Landmark |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/Itinerary.swift |
Foundation, Itinerary, DayPlan, Activity, Kind |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/ItineraryView.swift |
ItineraryView, DayView, ActivityList |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkDescriptionView.swift |
TaggingResponse, LandmarkDescriptionView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Utils.swift |
Logging, Padding, ReadabilityRoundedRectangle, Lookup |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/ItineraryPlanningView.swift |
ItineraryPlanningView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/MessageView.swift |
MessageView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/TripPlanningView.swift |
TripPlanningView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Landmarks/LandmarkDetailMapView.swift |
LandmarkDetailMapView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Landmarks/LandmarkFeaturedItemView.swift |
LandmarkFeaturedItemView |