Sample CodeiOS, iPadOS, Mac CatalystReviewed 2026-07-21View on Apple Developer

Sharing Your Location to Find a Park

At a glance

Item Summary
Purpose Ask for location access using a customizable location button.
App architecture A C/Objective-C header, Objective-C, Swift sample bundle with entry-bearing project variants Park Finder (SwiftUI), Park Finder (UIKit), each leading to CoreLocation APIs.
Main patterns View-controller organization, Delegate or data-source callbacks, Coordinator, Binding-based state propagation
Project style 11 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model Source-visible mechanisms: SwiftUI state property wrapper.
Key frameworks/packages UIKit, CoreLocation, MapKit, SwiftUI, CoreLocationUI; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── Park Finder (UIKit)/
│   └── Park Finder/
│       ├── main.m
│       ├── AppDelegate.h
│       ├── AppDelegate.m
│       ├── SceneDelegate.m
│       ├── ViewController.m
│       ├── SceneDelegate.h
│       └── ViewController.h
├── Park Finder (SwiftUI)/
│   └── Park Finder/
│       ├── ParkFinder.swift
│       ├── ContentView.swift
│       ├── Coordinator.swift
│       └── MapView.swift
└── Configuration/
    └── SampleCode.xcconfig

Structure observations

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

Overall architecture

Reference code

Park Finder (UIKit)/Park Finder/main.m:11 — architecture anchor

int main(int argc, char * argv[]) {
    NSString * appDelegateClassName;
    @autoreleasepool {
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
    }
    return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}

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

Ownership evidence

Park Finder (SwiftUI)/Park Finder/ContentView.swift:13 — stored dependency or nearest verified ownership anchor

struct ContentView: View {
    @State var manager = CLLocationManager()
    // ...
}
Owner Object or state Relationship Mutation authority
ContentView CLLocationManager (manager) owns wrapper-managed state App/module collaborators
Coordinator MapView (parent) stores or receives App/module collaborators
MapView CLLocationManager (manager) borrows mutable state The upstream binding owner is authoritative
MapView MKMapView (map) creates and retains 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.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

@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.

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. Park Finder (SwiftUI)/Park Finder/ContentView.swift:13
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (UIKit)/Park Finder/AppDelegate.h:8
Source import CoreLocation The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (SwiftUI)/Park Finder/ContentView.swift:10
Source import MapKit The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (SwiftUI)/Park Finder/Coordinator.swift:9
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (SwiftUI)/Park Finder/ContentView.swift:8
Source import CoreLocationUI The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (SwiftUI)/Park Finder/ContentView.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. Park Finder (UIKit)/Park Finder/ViewController.m: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

Park Finder (UIKit)/Park Finder/AppDelegate.h:10 — representative type boundary

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@end
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
ContentView User-interface presentation and input forwarding View
Coordinator Cross-object flow or session coordination NSObject, CLLocationManagerDelegate
MapView User-interface presentation and input forwarding UIViewRepresentable
SceneDelegate Receives callback-driven events UIResponder, UIWindowSceneDelegate
ViewController View lifecycle, callbacks, and feature coordination UIViewController, CLLocationManagerDelegate, MKMapViewDelegate
ParkFinder Represents a feature value or composable behavior App

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
addPins (Park Finder (SwiftUI)/Park Finder/Coordinator.swift:19) 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.
window (Park Finder (UIKit)/Park Finder/SceneDelegate.h:12) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
locationButton (Park Finder (UIKit)/Park Finder/ViewController.h:24) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
mapview (Park Finder (UIKit)/Park Finder/ViewController.h:25) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.

Reference code

Park Finder (SwiftUI)/Park Finder/Coordinator.swift:19 — representative boundary

    private func addPins(location: CLLocation) {
        // ...
                return
        // ...
    }

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
View lifecycle, callbacks, and feature coordination ViewController The source’s Controller suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
Receives callback-driven events AppDelegate, SceneDelegate The source’s Delegate suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, MapView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Park Finder (UIKit)/Park Finder/ViewController.h:21 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Delegate or data-source callbacks Park Finder (SwiftUI)/Park Finder/Coordinator.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Coordinator Park Finder (SwiftUI)/Park Finder/Coordinator.swift:11 A role-named coordinator centralizes cross-object flow.
Binding-based state propagation Park Finder (SwiftUI)/Park Finder/MapView.swift:13 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Main application flow

Reference code

Park Finder (UIKit)/Park Finder/ViewController.m:69addPins()

- (void)addPins:(CLLocation *)location {
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark*> *placemarks, NSError *error) {
        if (!placemarks) {
            return;
        } else if (placemarks && placemarks.count > 0) {
            CLPlacemark *placemark = [placemarks objectAtIndex:0];
            MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 1500, 1500);
            MKCoordinateRegion adjustedRegion = [self.mapview regionThatFits:viewRegion];
            [self.mapview setRegion:adjustedRegion animated:NO];

            MKLocalSearchRequest *searchRequest = [[MKLocalSearchRequest alloc] init];
            [searchRequest setNaturalLanguageQuery:@"Park"];
            [searchRequest setRegion:self.mapview.region];
            [searchRequest setRegion:viewRegion];

            MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:searchRequest];
            [localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *searcherror) {
                if (!searcherror) {
                    [self.mapview removeAnnotations: self.mapview.annotations];
                    for (MKMapItem *item in [response mapItems]) {
                        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
                        [annotation setCoordinate: item.placemark.coordinate];
                        [annotation setTitle: item.placemark.name];
                        [self.mapview addAnnotation:annotation];
                    }
                }
            }];
        }
    }];
}

Naming conventions

  • Types: Controller: ViewController; Coordinator: Coordinator; Delegate: AppDelegate, SceneDelegate; View: ContentView, MapView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: application, scene, sceneDidDisconnect, sceneDidBecomeActive, sceneWillResignActive, sceneWillEnterForeground, sceneDidEnterBackground, viewDidLoad.
  • Files: Park Finder (SwiftUI)/Park Finder/ParkFinder.swift, Park Finder (UIKit)/Park Finder/AppDelegate.h, Park Finder (SwiftUI)/Park Finder/ContentView.swift, Park Finder (UIKit)/Park Finder/AppDelegate.m, Park Finder (UIKit)/Park Finder/SceneDelegate.m, Park Finder (UIKit)/Park Finder/ViewController.m.

Architecture takeaways

  • main is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches UIKit, CoreLocation, MapKit, SwiftUI 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
Park Finder (UIKit)/Park Finder/main.m Cited implementation, Feature implementation
Park Finder (SwiftUI)/Park Finder/ContentView.swift Cited implementation, SwiftUI state property wrapper, CoreLocation, SwiftUI, CoreLocationUI, ContentView, ContentView_Previews
Park Finder (UIKit)/Park Finder/AppDelegate.h AppDelegate, UIKit
Park Finder (SwiftUI)/Park Finder/Coordinator.swift Cited implementation, Coordinator, MapKit
Park Finder (UIKit)/Park Finder/SceneDelegate.h window, SceneDelegate
Park Finder (UIKit)/Park Finder/ViewController.h locationButton, mapview, ViewController
Park Finder (SwiftUI)/Park Finder/MapView.swift Cited implementation, MapView
Park Finder (UIKit)/Park Finder/ViewController.m Foundation, ViewController
Park Finder (SwiftUI)/Park Finder/ParkFinder.swift ParkFinder
Park Finder (UIKit)/Park Finder/AppDelegate.m AppDelegate
Park Finder (UIKit)/Park Finder/SceneDelegate.m SceneDelegate