Sample CodeiOS, iPadOSReviewed 2026-07-21View on Apple Developer

Developing a browser app that uses an alternative browser engine

At a glance

Item Summary
Purpose Create a browser app and associated extensions.
App architecture A C/Objective-C header, Objective-C, Swift sample with the source-visible chain AlertManagerContentViewBrowserPageViewModelServiceProviderBrowserEngineKit APIs.
Main patterns Model-View-ViewModel, View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, SwiftUI environment injection, Binding-based state propagation
Project style 38 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── BrowserExample/
    ├── BrowserApp/
    │   ├── AlertManager.swift
    │   ├── BrowserApp.swift
    │   ├── BrowserPageViewModel.swift
    │   ├── TabViewModel.swift
    │   └── BrowserPage.swift
    ├── NetworkingExtension/
    │   └── NetworkingExtension.swift
    ├── RenderingExtension/
    │   └── RenderingExtension.swift
    ├── WebContentExtension/
    │   └── WebContentExtension.swift
    └── CustomBrowserEngine/
        ├── UIProcess/
        │   ├── WebView.swift
        │   └── WebContentView.swift
        ├── XPC/
        │   └── XPCCodable.swift
        └── NetworkProcess/
            └── NetworkSession.swift

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 14 project/configuration file(s) and 64 source declaration(s).

Overall architecture

Reference code

BrowserExample/BrowserApp/AlertManager.swift:48 — architecture anchor

 @main

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

Ownership and state

Ownership evidence

BrowserExample/BrowserApp/AlertManager.swift:13 — stored dependency or nearest verified ownership anchor

public struct Alert: Identifiable {
    // ...
  public var id = UUID()
    // ...
}
Owner Object or state Relationship Mutation authority
Alert UUID (id) owns value state App/module collaborators
Alert String (title) owns value state App/module collaborators
Alert String (message) owns value state App/module collaborators
Alert Array (buttons) owns value state 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

BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift:23 — representative type boundary

public protocol WebViewUIDelegate: AnyObject {
  func webViewDidStartLoading(_ webView: WebView)
  func webViewDidStopLoading(_ webView: WebView)
}
Type Responsibility Depends on or conforms to
MyApp Application entry and top-level composition App
BrowserApp Application entry and top-level composition App
WebViewUIDelegate Defines a capability or collaboration contract AnyObject
ServiceProvider Defines a capability or collaboration contract Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
AlertManager Long-lived feature or framework coordination ObservableObject
BrowserPageViewModel UI-facing state and feature coordination ObservableObject
TabViewModel UI-facing state and feature coordination ObservableObject
WebView User-interface presentation and input forwarding UIView
TabContentView User-interface presentation and input forwarding View

The source explicitly defines local protocol relationships: BrowserExtensionTaskXPCCodable, WebContentExtensionTaskXPCCodable, WebContentExtensionBootstrapCommandXPCCodable, HostingHandleMessageXPCCodable, IOSurfaceMessageXPCCodable, NetworkExtensionTaskXPCCodable.

Access control

Symbol Access Verified effect Likely rationale
log (BrowserExample/BrowserApp/ActivityViewButton.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.
isPresented (BrowserExample/BrowserApp/ActivityViewButton.swift:34) 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.
id (BrowserExample/BrowserApp/AlertManager.swift:13) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
title (BrowserExample/BrowserApp/AlertManager.swift:14) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

BrowserExample/BrowserApp/ActivityViewButton.swift:12 — representative boundary

private let log = Logger(subsystem: Constants.logSubsystem, category: String(describing: ActivityViewController.self))

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 BrowserApp, MyApp The source’s App suffix makes this role explicit.
Represents or runs a user/system command WebContentExtensionBootstrapCommand The source’s Command suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ActivityViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events WebViewUIDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination AlertManager The source’s Manager suffix makes this role explicit.
Supplies a capability or framework resource ServiceProvider The source’s Provider suffix makes this role explicit.
Owns a session-scoped interaction NetworkSession The source’s Session suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel BrowserExample/BrowserApp/BrowserPageViewModel.swift:15 Role-named view models keep UI-facing state or coordination outside view declarations.
View-controller organization BrowserExample/BrowserApp/ActivityViewButton.swift:53 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction BrowserExample/CustomBrowserEngine/Shared/BrowserExtensionProxy.swift:14 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks BrowserExample/BrowserApp/BrowserPageViewModel.swift:93 Callback protocols invert event delivery back into the sample’s owner.
SwiftUI environment injection BrowserExample/BrowserApp/AlertManager.swift:64 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation BrowserExample/BrowserApp/BrowserPage.swift:339 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: BrowserApp, MyApp; Command: WebContentExtensionBootstrapCommand; Controller: ActivityViewController; Delegate: WebViewUIDelegate; Manager: AlertManager; Provider: ServiceProvider; Session: NetworkSession; View: ContentView, TabContentView, WebContentView, WebView.
  • Protocols: WebViewUIDelegate, ServiceProvider, WebViewNavigationNelegate, XPCCodable, XPCEncodable, XPCDecodable.
  • Methods: present, dismissCurrentAlert, body, makeActions, makeMessage, presentingAlerts, open, handle.
  • Files: BrowserExample/BrowserApp/AlertManager.swift, BrowserExample/BrowserApp/BrowserApp.swift, BrowserExample/BrowserApp/BrowserPageViewModel.swift, BrowserExample/BrowserApp/TabViewModel.swift, BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift, BrowserExample/BrowserApp/BrowserPage.swift.

Architecture takeaways

  • AlertManager is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches XPC, BrowserEngineKit, CustomBrowserEngine, 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
BrowserExample/BrowserApp/AlertManager.swift Alert, Button, MyApp, ContentView, AlertManager, AlertPresenter
BrowserExample/BrowserApp/BrowserApp.swift BrowserApp
BrowserExample/NetworkingExtension/NetworkingExtension.swift CustomNetworkingExtension
BrowserExample/RenderingExtension/RenderingExtension.swift CustomRenderingExtension
BrowserExample/WebContentExtension/WebContentExtension.swift CustomWebContentExtension
BrowserExample/BrowserApp/BrowserPageViewModel.swift BrowserPageViewModel, NavigationDirection
BrowserExample/BrowserApp/TabViewModel.swift TabViewModel
BrowserExample/CustomBrowserEngine/UIProcess/WebView.swift WebViewNavigationNelegate, WebViewUIDelegate, WebView, WebViewNavigationStack
BrowserExample/BrowserApp/BrowserPage.swift TabContentView, BrowserPage, WebViewRepresentable, BookmarksList, DismissButton
BrowserExample/CustomBrowserEngine/XPC/XPCCodable.swift XPCCodable, XPCEncodable, XPCDecodable, XPCEncoder, XPCDecoder