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 | Actor-isolated state |
| Project style | 22 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
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 {
// ...
}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.
Class and protocol design
FoundationModelsTripPlanner/FoundationModelsTripPlanner/FoundationModelsTripPlannerApp.swift:11 — representative type boundary
struct FoundationModelsTripPlannerApp: App {
// ...
}| 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 |
|---|---|---|
| Actor-isolated state | FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/FindPointsOfInterestTool.swift:18 |
Actor annotations make the concurrency ownership boundary explicit. |
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 |
FoundationModelsTripPlannerApp |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/Effects.swift |
HeaderStyle, CardModifier, TagStyleModifier, RationaleModifier, ItineraryModifier, BlurredBackgroundModifier, ActivityIcon |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/ItineraryView.swift |
ItineraryView, DayView, ActivityList |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkTripView.swift |
LandmarkTripView, ItineraryButton, ItineraryHeader |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Views/Itinerary/LandmarkDescriptionView.swift |
TaggingResponse, LandmarkDescriptionView |
FoundationModelsTripPlanner/FoundationModelsTripPlanner/Model/Itinerary/Itinerary.swift |
Itinerary, DayPlan, Activity, Kind |
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 |