Interacting with nearby points of interest
At a glance
| Item | Summary |
|---|---|
| Purpose | Provide automatic search completions for a partial search query, search the map for relevant locations nearby, and retrieve details for selected points of interest. |
| App architecture | A Swift sample bundle with entry-bearing project variants PointsOfInterest-UIKit, PointsOfInterest, each leading to MapKit APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Service object, Binding-based state propagation |
| Project style | 25 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: Task, await suspension point, @MainActor, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, @Observable. |
| Key frameworks/packages | MapKit, SwiftUI, Foundation, UIKit, OSLog; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── PointsOfInterest-UIKit/
│ ├── AppDelegate.swift
│ ├── BaseMapItemViewController.swift
│ ├── SearchResultsViewController.swift
│ ├── MapViewController.swift
│ ├── SceneDelegate.swift
│ └── SidebarViewController.swift
├── PointsOfInterest/
│ ├── PointsOfInterestApp.swift
│ ├── ContentView.swift
│ ├── MapModel.swift
│ ├── MapView.swift
│ └── NavigationModel.swift
└── Shared/
└── MapSearchConfiguration.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 7 project/configuration file(s) and 29 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["PointsOfInterest-UIKit"]
V2["PointsOfInterest"]
Boundary["MapKit APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Reference code
PointsOfInterest-UIKit/AppDelegate.swift:10 — architecture anchor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
}Interpretation
The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.
Ownership and state
classDiagram
Row *-- String : header
Row o-- MKMapItem : mapItem
Row o-- UICollectionViewDiffableDataSource : dataSource
Row o-- UICollectionView : collectionView
Ownership evidence
PointsOfInterest-UIKit/BaseMapItemViewController.swift:18 — stored dependency or nearest verified ownership anchor
struct Row: Hashable {
var header: String?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Row |
String (header) |
owns value state | App/module collaborators |
Row |
MKMapItem (mapItem) |
stores or receives | App/module collaborators |
Row |
UICollectionViewDiffableDataSource (dataSource) |
stores or receives | App/module collaborators |
Row |
UICollectionView (collectionView) |
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 |
|---|---|---|---|
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | PointsOfInterest-UIKit/MapViewController.swift:90 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | PointsOfInterest-UIKit/MapViewController.swift:95 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | PointsOfInterest-UIKit/SearchResultsViewController.swift:60 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | PointsOfInterest-UIKit/SearchResultsViewController.swift:60 |
@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
PointsOfInterest-UIKit/MapViewController.swift:90 — representative execution boundary
Task {
// ...
let request = MKMapItemRequest(mapFeatureAnnotation: annotation)
// ...
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | PointsOfInterest/ContentView.swift:12 |
| State propagation | @Observable |
Observation macro publishes source-visible changes. | PointsOfInterest/MapModel.swift:13 |
| Source import | MapKit |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/BaseMapItemViewController.swift:9 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/SearchResultsViewController.swift:10 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/BaseMapItemViewController.swift:8 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/AppDelegate.swift:8 |
| Source import | OSLog |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/MapViewController.swift:10 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | PointsOfInterest-UIKit/SidebarViewController.swift:11 |
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
PointsOfInterest-UIKit/SearchResultsViewController.swift:178 — representative type boundary
@MainActor
protocol SearchResultsViewControllerDelegate: NSObjectProtocol {
// ...
func searchResultsViewController(_ viewController: SearchResultsViewController, didUpdate searchResults: [MKMapItem])
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
PointsOfInterestApp |
Application entry and top-level composition | App |
SearchResultsViewControllerDelegate |
Defines a capability or collaboration contract | NSObjectProtocol |
BaseMapItemViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
SearchResultsViewController |
View lifecycle, callbacks, and feature coordination | BaseMapItemViewController |
MapViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
SceneDelegate |
Receives callback-driven events | UIResponder, UIWindowSceneDelegate |
SidebarViewController |
View lifecycle, callbacks, and feature coordination | BaseMapItemViewController |
ContentView |
User-interface presentation and input forwarding | View |
MapModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
The source explicitly defines local protocol relationships: SidebarViewController → SearchResultsViewControllerDelegate.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
configureViewHierarchy (PointsOfInterest-UIKit/BaseMapItemViewController.swift:40) |
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. |
createLayout (PointsOfInterest-UIKit/BaseMapItemViewController.swift:46) |
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. |
configureDataSource (PointsOfInterest-UIKit/BaseMapItemViewController.swift:54) |
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. |
mapView (PointsOfInterest-UIKit/MapViewController.swift:15) |
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. |
Reference code
PointsOfInterest-UIKit/BaseMapItemViewController.swift:40 — representative boundary
private func configureViewHierarchy() {
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout())
collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(collectionView)
}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 | PointsOfInterestApp |
The source’s App suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | BaseMapItemViewController, MapViewController, SearchResultsViewController, SidebarViewController |
The source’s Controller suffix makes this role explicit. |
| Supplies data through a callback contract | SearchDataSource |
The source’s DataSource suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, SceneDelegate, SearchResultsViewControllerDelegate |
The source’s Delegate suffix makes this role explicit. |
| Feature data or observable state | MapModel, NavigationModel |
The source’s Model suffix makes this role explicit. |
| Framework-facing operations | LocationService |
The source’s Service suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, MapItemRowView, MapView, SearchCompletionItemView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | PointsOfInterest-UIKit/BaseMapItemViewController.swift:12 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | PointsOfInterest-UIKit/SidebarViewController.swift:194 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | PointsOfInterest-UIKit/AppDelegate.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
| Service object | Shared/LocationService.swift:14 |
A role-named service contains framework-facing operations. |
| Binding-based state propagation | PointsOfInterest/SideBarListViewSection.swift:14 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: PointsOfInterestApp; Controller: BaseMapItemViewController, MapViewController, SearchResultsViewController, SidebarViewController; DataSource: SearchDataSource; Delegate: AppDelegate, SceneDelegate, SearchResultsViewControllerDelegate; Model: MapModel, NavigationModel; Service: LocationService; View: ContentView, MapItemRowView, MapView, SearchCompletionItemView, SettingsView.
- Protocols:
SearchResultsViewControllerDelegate. - Methods:
viewDidLoad,configureViewHierarchy,createLayout,configureDataSource,updateCollectionViewSnapshot,configureHeaderCell,configureResultCell,presentMapItemDetail. - Files:
PointsOfInterest-UIKit/AppDelegate.swift,PointsOfInterest/PointsOfInterestApp.swift,PointsOfInterest-UIKit/BaseMapItemViewController.swift,PointsOfInterest-UIKit/SearchResultsViewController.swift,Shared/MapSearchConfiguration.swift,PointsOfInterest-UIKit/MapViewController.swift.
Architecture takeaways
AppDelegateis the main source-visible entry or composition anchor for this sample.- Framework work reaches MapKit, SwiftUI, UIKit, SwiftData 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.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
PointsOfInterest-UIKit/AppDelegate.swift |
Cited implementation, UIKit, AppDelegate |
PointsOfInterest-UIKit/BaseMapItemViewController.swift |
Cited implementation, BaseMapItemViewController, MapKit, Foundation, Section, Row |
PointsOfInterest-UIKit/SearchResultsViewController.swift |
SearchResultsViewControllerDelegate, @MainActor, Task closure isolated to MainActor, SwiftUI, SearchResultsViewController |
PointsOfInterest-UIKit/MapViewController.swift |
Cited implementation, Task, await suspension point, OSLog, MapViewController |
PointsOfInterest-UIKit/SidebarViewController.swift |
Cited implementation, SwiftData, SidebarViewController |
Shared/LocationService.swift |
LocationService |
PointsOfInterest/SideBarListViewSection.swift |
Cited implementation, SidebarListViewSection |
PointsOfInterest/ContentView.swift |
SwiftUI state property wrapper, ContentView |
PointsOfInterest/MapModel.swift |
@Observable, MapModel |
PointsOfInterest/PointsOfInterestApp.swift |
PointsOfInterestApp |
Shared/MapSearchConfiguration.swift |
MapSearchConfiguration, RegionPriority, SearchResultType, PointOfInterestOptions, AddressOptions |
PointsOfInterest-UIKit/SceneDelegate.swift |
SceneDelegate |
PointsOfInterest/MapView.swift |
MapView |
PointsOfInterest/NavigationModel.swift |
NavigationModel |
PointsOfInterest/SearchCompletionItemView.swift |
SearchCompletionItemView |
PointsOfInterest/SidebarListView.swift |
SidebarListView |