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

Synchronizing files using file provider extensions

At a glance

Item Summary
Purpose Make remote files available in macOS and iOS, and synchronize their states by using file provider extensions.
App architecture A C/Objective-C header, Swift sample bundle with entry-bearing project variants FruitBasket-iOS, FruitBasket, each leading to FileProvider APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Service object, Central store, Actor-isolated state
Project style 62 scanned source file(s) across C/Objective-C header, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── FruitBasket-iOS/
│   ├── FruitBasketApp.swift
│   ├── SettingsView.swift
│   ├── AddDomain.swift
│   └── ContentView.swift
├── FruitBasket/
│   └── AppDelegate.swift
├── Common/
│   ├── AccountService.swift
│   ├── DomainService.swift
│   ├── EnumerationView.swift
│   └── ContentBasedChunkStore.swift
├── Provider/
│   └── main.swift
├── Action/
│   └── ConflictViewController.swift
└── Server/
    └── ItemDatabase.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, Swift.
  • The verified tree contains 20 project/configuration file(s) and 182 source declaration(s).

Overall architecture

Reference code

FruitBasket-iOS/FruitBasketApp.swift:10 — architecture anchor

@main
struct FruitBasketApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView().navigationTitle("Domains")
        }
    }
}

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

Common/AccountService.swift:15 — stored dependency or nearest verified ownership anchor

        public let identifier: String
        public let secret: String
        public let displayName: String
        public let rootItem: DomainService.Entry
        // This is a random number this sample assigns at account creation and uses to test
        // rank expiration.
        public let tokenCheckNumber: Int64
Owner Object or state Relationship Mutation authority
Account String (identifier) owns value state Initialized by the owner; the binding is immutable
Account String (secret) owns value state Initialized by the owner; the binding is immutable
Account String (displayName) owns value state Initialized by the owner; the binding is immutable
Account Entry (rootItem) 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

Common/ContentBasedChunkStore.swift:11 — representative type boundary

public protocol ContentBasedChunkStore {
    func chunkExists(sha256OfChunk: Data) -> Bool
    func createChunk(sha256OfChunk: Data, chunkData: Data) throws
    func retrieveChunk(sha256OfChunk: Data) throws -> Data?

    func close()
}
Type Responsibility Depends on or conforms to
FruitBasketApp Application entry and top-level composition App
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate, NSXPCListenerDelegate
ContentBasedChunkStore Defines a capability or collaboration contract Concrete collaborators/imported frameworks
ConcreteActionViewController Defines a capability or collaboration contract NSViewController
MillisecondTransformer Transforms feature data or representations ValueTransformer
PercentageTransformer Transforms feature data or representations ValueTransformer
AccountService Framework-facing operations Concrete collaborators/imported frameworks
DomainService Framework-facing operations Concrete collaborators/imported frameworks
EnumerationView User-interface presentation and input forwarding View
SettingsView User-interface presentation and input forwarding View

The source explicitly defines local protocol relationships: AuthenticationViewControllerConcreteActionViewController, ConflictViewControllerConcreteActionViewController, InfoParameterJSONParameter, ListAccountParameterJSONParameter, CreateAccountParameterJSONParameter, RemoveAccountParameterJSONParameter.

Access control

Symbol Access Verified effect Likely rationale
logger (Action/ActionViewController.swift:19) 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.
prepare (Action/ActionViewController.swift:42) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
prepare (Action/ActionViewController.swift:50) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
logger (Action/AuthenticationViewController.swift:15) 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.

Reference code

Action/ActionViewController.swift:19 — representative boundary

    private let logger = Logger(subsystem: "com.example.apple-samplecode.FruitBasket", category: "action")

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 FruitBasketApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ActionViewController, AuthenticationViewController, ConcreteActionViewController, ConflictViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Observes and relays feature changes DomainObserver The source’s Observer suffix makes this role explicit.
Framework-facing operations AccountService, DomainService The source’s Service suffix makes this role explicit.
Centralized state or persistence access ContentBasedChunkStore, LocalContentBasedChunkStore The source’s Store suffix makes this role explicit.
Transforms feature data or representations EditDateValueTransformer, MillisecondTransformer, PercentageTransformer The source’s Transformer suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Action/ActionViewController.swift:18 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction Action/AuthenticationViewController.swift:14 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks Extension/Extension+Servicing.swift:51 Callback protocols invert event delivery back into the sample’s owner.
Service object Common/AccountService.swift:13 A role-named service contains framework-facing operations.
Central store Common/ContentBasedChunkStore.swift:11 A store-named type centralizes feature state or persistence.
Actor-isolated state FruitBasket/AppDelegate.swift:23 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: FruitBasketApp; Controller: ActionViewController, AuthenticationViewController, ConcreteActionViewController, ConflictViewController, EditDomainWindowController; Delegate: AppDelegate; Observer: DomainObserver; Service: AccountService, DomainService; Store: ContentBasedChunkStore, LocalContentBasedChunkStore; Transformer: EditDateValueTransformer, MillisecondTransformer, PercentageTransformer; View: BlockedProcessesEditorView, ContentView, DomainDetailView, EnumerationView, RemoteAccountView.
  • Protocols: ContentBasedChunkStore, ConcreteActionViewController, JSONParameter, FruitBasketServiceV1, XAttrGettable, DispatchBackend, BackendCallRegistration, XAttrSettable.
  • Methods: notify, serverChangeReceived, signalItems, setupDomainPipe, setupDomainPipeAsync, handleDomainPipeError, itemsChanged, updateItemCount.
  • Files: FruitBasket-iOS/FruitBasketApp.swift, FruitBasket/AppDelegate.swift, Common/AccountService.swift, Common/DomainService.swift, Common/EnumerationView.swift, FruitBasket-iOS/SettingsView.swift.

Architecture takeaways

  • FruitBasketApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Common, FileProvider, SwiftUI, SQLite 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
FruitBasket-iOS/FruitBasketApp.swift FruitBasketApp
FruitBasket/AppDelegate.swift Notifier, AppDelegate, MillisecondTransformer, PercentageTransformer
Common/AccountService.swift AccountService, Account, InfoParameter, InfoReturn, ListAccountParameter, ListAccountReturn, CreateAccountParameter, CreateAccountReturn, RemoveAccountParameter, RemoveAccountReturn, ResetSyncAnchorParameter, ResetSyncAnchorReturn
Common/DomainService.swift JSONMethod, JSONParameter, DomainService, EntryType, Version, ConflictVersion, RankToken, ItemIdentifier, CodingKeys, EntryMetadata, ValidEntries, ExtendedAttributes, Entry, UserInfo, ContentStorageType, CodingKeys, ContentSha256S, ContentStorageTypeParameter, ListFolderParameter, ListFolderReturn, ListChangesParameter, ListChangesReturn, LatestRankParameter, LatestRankReturn, CreateParameter, ConflictStrategy, CreateReturn, ModifyContentsParameter, ModifyContentsReturn, CreateDataChunkParameter, CreateDataChunkReturn, GetDataChunkParameter, GetDataChunkReturn, CheckChunkExistsParameter, CheckChunkExistsReturn, ModifyMetadataParameter, ModifyMetadataReturn, FetchItemParameter, FetchItemReturn, DownloadItemParameter, DownloadItemReturn, FetchItemContentStorageTypeParameter, FetchItemContentStorageTypeReturn, DeleteItemParameter, DeleteItemReturn, TrashItemParameter, TrashItemReturn, UpdateThumbnailParameter, UpdateThumbnailReturn, FetchThumbnailParameter, FetchThumbnailReturn, ConflictVersionsParameter, ConflictVersionsReturn, ResolveConflictVersionsParameter, ResolveConflictVersionsReturn, CreateConflictParameter, CreateConflictReturn, MarkParameter, MarkReturn, PingLockParameter, PingLockReturn, RemoveLockParameter, RemoveLockReturn, ForceLockParameter, ForceLockReturn, PushRegistrationParameter, PushRegistrationReturn, PushDevice, SimulatedError, AccessType, SimulateErrorParameter, SimulateErrorReturn, SimulateErrorListParameter, SimulateErrorListReturn, ListLocksParameter, ListLocksReturn, Lock
Common/EnumerationView.swift EnumerationView, EnumerationType, EnumeratorObservableObject, State, Entry, ItemType, ItemRow
FruitBasket-iOS/SettingsView.swift SettingsView, SubSettings, ServiceBrowser, ServiceEntry, State, HostListEntry, HostList
Common/ContentBasedChunkStore.swift ContentBasedChunkStore, LocalContentBasedChunkStore, ChunkFileLocator, HexEncodingOptions
Provider/main.swift Feature implementation
Action/ConflictViewController.swift ConflictViewController, ConflictDescriptor, EditDateValueTransformer
FruitBasket-iOS/AddDomain.swift AccountFetcher, AddDomain, RemoteAccountView, NavigationPane, ViewState, AccountList, Fetching