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

Filtering traffic by URL

At a glance

Item Summary
Purpose Perform fast and robust filtering of full URLs by managing URL filtering configurations.
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
Project style 21 scanned source file(s) across Shell, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: async declaration or closure, Sendable or @Sendable, @MainActor, Task; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages Foundation, OSLog, SwiftBloomFilter, SwiftUI, NetworkExtension; these are source dependencies, not architecture labels.

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 {
    @Environment(\.scenePhase) private var scenePhase
    // ...
}

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.

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
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. BloomFilterTool/BloomFilterTool/BloomFilterTool.swift:53
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. BloomFilterTool/BloomFilterTool/pir_database.pb.swift:46
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:17
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:114

@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

BloomFilterTool/BloomFilterTool/BloomFilterTool.swift:53 — representative execution boundary

    mutating func run() async throws {
        // ...
        if filterOutputFile == nil {
            filterOutputFile = URL.currentDirectory().appending(path: BloomFilterToolDefaults.filterOutputFileName)
        }
        // ...
    }

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 @Observable Observation macro publishes source-visible changes. SimpleURLFilter/SimpleURLFilter/Model/Configuration.swift:11
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift:13
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. BloomFilterTool/BloomFilterTool/BloomFilterTool.swift:9
Source import OSLog The cited file imports this module; runtime use and architectural role are not inferred. SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:10
Source import SwiftBloomFilter The cited file imports this module; runtime use and architectural role are not inferred. BloomFilterTool/BloomFilterTool/BloomFilterTool.swift:11
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. SimpleURLFilter/SimpleURLFilter/SimpleURLFilterApp.swift:8
Source import NetworkExtension The cited file imports this module; runtime use and architectural role are not inferred. SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift:9
Source import Testing The cited file imports this module; runtime use and architectural role are not inferred. SwiftBloomFilter/SwiftBloomFilterTests/FNVHashTests.swift:8

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

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

@main
struct SimpleURLFilterApp: App {
    @Environment(\.scenePhase) private var scenePhase
    // ...
}
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.

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 Cited implementation, SimpleURLFilterApp, SwiftUI state property wrapper, SwiftUI
BloomFilterTool/BloomFilterTool/pir_database.pb.swift Cited implementation, Sendable or @Sendable, _GeneratedWithProtocGenSwiftVersion, _2, Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabaseRow, Apple_SwiftHomomorphicEncryption_Pir_V1_KeywordDatabase
SimpleURLFilter/SimpleURLFilter/Model/ConfigurationModel.swift Cited implementation, @MainActor, Task, OSLog, NetworkExtension, ConfigurationModel, ConfigurationError
SimpleURLFilter/SimpleURLFilter/View Models/ContentViewModel.swift ContentViewModel, ActivationButtonAction
SimpleURLFilter/SimpleURLFilter/Views/ConfigurationView.swift Cited implementation, ConfigurationView, Field, ValidationError, PrefilterFetchInterval
BloomFilterTool/BloomFilterTool/BloomFilterTool.swift async declaration or closure, Foundation, SwiftBloomFilter, BloomFilterToolDefaults, BloomFilterTool, RuntimeError
SimpleURLFilter/SimpleURLFilter/Model/Configuration.swift @Observable, Configuration
SwiftBloomFilter/SwiftBloomFilterTests/FNVHashTests.swift Testing, FNVHashTests
SimpleURLFilter/SimpleURLFilterExtension/URLFilterControlProvider.swift ProviderFilterError, URLFilterControlProvider
SimpleURLFilter/SimpleURLFilter/Views/ContentView.swift ContentView
SwiftBloomFilter/SwiftBloomFilter/BloomFilter.swift BloomFilterError, BloomFilter, CodingKeys
SimpleURLFilter/SimpleURLFilter/Model/ActivityState.swift ActivityState
SimpleURLFilter/SimpleURLFilter/Model/FilterStatus.swift FilterStatus
SimpleURLFilter/SimpleURLFilter/Utils/ErrorDetails.swift ErrorDetails
SwiftBloomFilter/SwiftBloomFilterTests/SwiftBloomFilterTests.swift SwiftBloomFilterTests, BloomFilterInternalsTests, BitTests
BloomFilterTool/BloomFilterTool/swift_protobuf.sh Feature implementation