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

Using the Bloom filter tool to configure a URL filter

At a glance

Item Summary
Purpose Create the files a URL filter needs for its Bloom prefilter.
App architecture A Shell, Swift sample bundle with entry-bearing project variants BloomFilterTool, SimpleURLFilter, each leading to NetworkExtension APIs.
Main patterns Model-View-ViewModel, Binding-based state propagation, Actor-isolated state
Project style 21 scanned source file(s) across Shell, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── SimpleURLFilter/
│   ├── SimpleURLFilter/
│   │   ├── SimpleURLFilterApp.swift
│   │   ├── View Models/
│   │   │   └── ContentViewModel.swift
│   │   ├── Views/
│   │   │   ├── ConfigurationView.swift
│   │   │   └── ContentView.swift
│   │   └── Model/
│   │       ├── ConfigurationModel.swift
│   │       ├── ActivityState.swift
│   │       ├── Configuration.swift
│   │       └── FilterStatus.swift
│   └── SimpleURLFilterExtension/
│       └── URLFilterControlProvider.swift
├── BloomFilterTool/
│   └── BloomFilterTool/
│       ├── BloomFilterTool.swift
│       └── pir_database.pb.swift
└── SwiftBloomFilter/
    └── SwiftBloomFilter/
        └── BloomFilter.swift

Structure observations

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

Overall architecture

Reference code

SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift:11 — architecture anchor

@main
struct SimpleURLFilterApp: App {
    // ...
}

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

SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift:14 — stored dependency or nearest verified ownership anchor

@main
struct SimpleURLFilterApp: App {
    // ...
    @State private var configurationModel: ConfigurationModel
    // ...
}
Owner Object or state Relationship Mutation authority
SimpleURLFilterApp ConfigurationModel (configurationModel) owns wrapper-managed state Owning lexical scope
SimpleURLFilterApp ContentViewModel (viewModel) owns wrapper-managed state Owning lexical scope
URLFilterControlProvider BloomFilter (filter) stores or receives App/module collaborators
URLFilterControlProvider Logger (log) 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

SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift:12 — representative type boundary

struct SimpleURLFilterApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
SimpleURLFilterApp Application entry and top-level composition App
URLFilterControlProvider Supplies a capability or framework resource Concrete collaborators/imported frameworks
ContentViewModel UI-facing state and feature coordination Concrete collaborators/imported frameworks
ConfigurationView User-interface presentation and input forwarding View
ConfigurationModel Feature data or observable state Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
ProviderFilterError Represents feature failure conditions Error
BloomFilterToolDefaults Represents a feature value or composable behavior Concrete collaborators/imported frameworks
BloomFilterTool Represents a feature value or composable behavior AsyncParsableCommand
RuntimeError Represents feature failure conditions Error, CustomStringConvertible

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
_protobuf_package (BloomFilterTool/BloomFilterTool/pir_database.pb.swift:78) fileprivate Use is restricted to this source file. Inference: share with same-file helpers or extensions without exposing the symbol module-wide.
sharedFilterManager (SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:23) 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.
log (SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:24) 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.
ConfigurationModel (SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:26) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

BloomFilterTool/BloomFilterTool/pir_database.pb.swift:78 — representative boundary

fileprivate let _protobuf_package = "apple.swift_homomorphic_encryption.pir.v1"

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 SimpleURLFilterApp The source’s App suffix makes this role explicit.
Feature data or observable state ConfigurationModel The source’s Model suffix makes this role explicit.
Supplies a capability or framework resource URLFilterControlProvider The source’s Provider suffix makes this role explicit.
User-interface presentation and input forwarding ConfigurationView, ContentView The source’s View suffix makes this role explicit.
UI-facing state and feature coordination ContentViewModel The source’s ViewModel suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel SimpleURLFilter/SimpleURLFilter/View Models/ContentViewModel.swift:17 Role-named view models keep UI-facing state or coordination outside view declarations.
Binding-based state propagation SimpleURLFilter/SimpleURLFilter/Views/ConfigurationView.swift:21 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor-isolated state SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:17 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: SimpleURLFilterApp; Model: ConfigurationModel; Provider: URLFilterControlProvider; View: ConfigurationView, ContentView; ViewModel: ContentViewModel.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: content, loadBloomFilter, filterTag, start, stop, fetchPrefilter, run, readTo.
  • Files: SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift, SimpleURLFilter/SimpleURLFilterExtension/URLFilterControlProvider.swift, BloomFilterTool/BloomFilterTool/BloomFilterTool.swift, SimpleURLFilter/SimpleURLFilter/View Models/ContentViewModel.swift, SimpleURLFilter/SimpleURLFilter/Views/ConfigurationView.swift, SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift.

Architecture takeaways

  • SimpleURLFilterApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftBloomFilter, SwiftUI, NetworkExtension, Testing 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
SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift SimpleURLFilterApp
SimpleURLFilter/SimpleURLFilterExtension/URLFilterControlProvider.swift ProviderFilterError, URLFilterControlProvider
BloomFilterTool/BloomFilterTool/BloomFilterTool.swift BloomFilterToolDefaults, BloomFilterTool, RuntimeError
SimpleURLFilter/SimpleURLFilter/View Models/ContentViewModel.swift ContentViewModel, ActivationButtonAction
SimpleURLFilter/SimpleURLFilter/Views/ConfigurationView.swift ConfigurationView, Field, ValidationError, PrefilterFetchInterval
SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift ConfigurationModel, ConfigurationError
BloomFilterTool/BloomFilterTool/pir_database.pb.swift _GeneratedWithProtocGenSwiftVersion, _2, Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabaseRow, Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase
SimpleURLFilter/SimpleURLFilter/Views/ContentView.swift ContentView
SwiftBloomFilter/SwiftBloomFilter/BloomFilter.swift BloomFilterError, BloomFilter, CodingKeys
SimpleURLFilter/SimpleURLFilter/Model/ActivityState.swift ActivityState