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

Interacting with a home automation network

At a glance

Item Summary
Purpose Find all the automation accessories in the primary home and control their state.
App architecture A Swift sample with the source-visible chain AppDelegateAccessoryViewHomeStoreHomeKit APIs.
Main patterns Protocol-oriented abstraction, Delegate or data-source callbacks, Central store
Project style 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── AccessoryFinder/
    ├── Homes/
    │   ├── HomeView.swift
    │   ├── HomeView+AccessoryDelegate.swift
    │   ├── HomeView+HomeDelegate.swift
    │   └── HomeView+HomeManagerDelegate.swift
    ├── AppDelegate.swift
    ├── Services/
    │   ├── ServiceView.swift
    │   └── ServiceView+AccessoryDelegate.swift
    ├── Accessories/
    │   ├── AccessoryView.swift
    │   └── AccessoryView+AccessoryDelegate.swift
    ├── Characteristics/
    │   ├── CharacteristicView.swift
    │   └── CharacteristicView+AccessoryDelegate.swift
    └── Model/
        └── HomeStore.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 18 source declaration(s).

Overall architecture

Reference code

AccessoryFinder/AppDelegate.swift:10 — architecture anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
    // ...
}

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

Ownership and state

Ownership evidence

AccessoryFinder/Homes/HomeView.swift:218 — stored dependency or nearest verified ownership anchor

struct Category: AccessoryGroup {
    var name: String
    var accessories: [HMAccessory]
}
Owner Object or state Relationship Mutation authority
Category String (name) owns value state App/module collaborators
Category Array (accessories) owns value state App/module collaborators
AppDelegate UIWindow (window) stores or receives App/module collaborators
AccessoryView UIBarButtonItem (identifyButton) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere

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

AccessoryFinder/Editors/NameEditor.swift:10 — representative type boundary

protocol NameEditDelegate: AnyObject {
    func updateName(_ name: String)
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate
NameEditDelegate Defines a capability or collaboration contract AnyObject
HomeView User-interface presentation and input forwarding UITableViewController
ServiceView User-interface presentation and input forwarding UITableViewController
AccessoryView User-interface presentation and input forwarding UITableViewController
CharacteristicView User-interface presentation and input forwarding UITableViewController
HomeStore Centralized state or persistence access NSObject
AccessoryGroup Defines a capability or collaboration contract Concrete collaborators/imported frameworks
GroupKey Defines a closed set of feature states or choices Concrete collaborators/imported frameworks
Category Represents a feature value or composable behavior AccessoryGroup

The source explicitly defines local protocol relationships: CategoryAccessoryGroup, AccessoryViewNameEditDelegate, HMRoomAccessoryGroup, ServiceViewNameEditDelegate.

Access control

Symbol Access Verified effect Likely rationale
AppDelegate (AccessoryFinder/AppDelegate.swift:11) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.
NameEditDelegate (AccessoryFinder/Editors/NameEditor.swift:10) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.
HomeView (AccessoryFinder/Homes/HomeView.swift:12) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.
ServiceView (AccessoryFinder/Services/ServiceView.swift:8) implicit internal No explicit modifier means the Swift declaration is internal to the module. Inference: app-target collaboration needs no exported library surface.

Reference code

AccessoryFinder/AppDelegate.swift:11 — representative boundary

class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
    // ...
}

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
Receives callback-driven events AppDelegate, NameEditDelegate The source’s Delegate suffix makes this role explicit.
Centralized state or persistence access HomeStore The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding AccessoryView, CharacteristicView, HomeView, ServiceView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Protocol-oriented abstraction AccessoryFinder/Homes/HomeView.swift:217 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks AccessoryFinder/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Central store AccessoryFinder/Model/HomeStore.swift:11 A store-named type centralizes feature state or persistence.

Naming conventions

  • Types: Delegate: AppDelegate, NameEditDelegate; Store: HomeStore; View: AccessoryView, CharacteristicView, HomeView, ServiceView.
  • Protocols: NameEditDelegate, AccessoryGroup.
  • Methods: changeSeg, reloadDisplayData, viewDidLoad, viewWillAppear, resetDisplay, tapAddAccessory, prepare, numberOfSections.
  • Files: AccessoryFinder/Homes/HomeView.swift, AccessoryFinder/AppDelegate.swift, AccessoryFinder/Services/ServiceView.swift, AccessoryFinder/Accessories/AccessoryView.swift, AccessoryFinder/Characteristics/CharacteristicView.swift, AccessoryFinder/Model/HomeStore.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches HomeKit, UIKit 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
AccessoryFinder/Homes/HomeView.swift HomeView, GroupKey, AccessoryGroup, Category
AccessoryFinder/AppDelegate.swift AppDelegate
AccessoryFinder/Services/ServiceView.swift ServiceView, Sections
AccessoryFinder/Accessories/AccessoryView.swift AccessoryView, Sections
AccessoryFinder/Characteristics/CharacteristicView.swift CharacteristicView, Sections
AccessoryFinder/Services/ServiceView+AccessoryDelegate.swift Feature implementation
AccessoryFinder/Model/HomeStore.swift HomeStore
AccessoryFinder/Accessories/AccessoryView+AccessoryDelegate.swift Feature implementation
AccessoryFinder/Characteristics/CharacteristicView+AccessoryDelegate.swift Feature implementation
AccessoryFinder/Homes/HomeView+AccessoryDelegate.swift Feature implementation