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

Implementing a store in your app using the StoreKit API

At a glance

Item Summary
Purpose Offer In-App Purchases and manage entitlements using signed transactions and status information.
App architecture A Swift sample with the source-visible chain SKDemoAppContentViewBoostStoreStoreKit APIs.
Main patterns Central store, Binding-based state propagation, Actor isolation
Project style 30 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: @MainActor, async declaration or closure, Task, Task.detached, actor; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, StoreKit, OSLog, SKDemoServer, Foundation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── SKDemo/
│   ├── SKDemoApp.swift
│   ├── In App Purchase/
│   │   └── Store.swift
│   ├── View/
│   │   ├── ContentView.swift
│   │   ├── Miscellaneous/
│   │   │   ├── CarItemStore.swift
│   │   │   └── ImageNameConstants.swift
│   │   ├── Stores/
│   │   │   ├── BoostStore.swift
│   │   │   └── SubscriptionStore.swift
│   │   ├── SelectedCarView.swift
│   │   └── SwiftUIMerchandisingView.swift
│   └── Model/
│       └── SKDemoPlusStatus.swift
└── SKDemoServer/
    └── Sources/
        ├── Consumable.swift
        └── Server.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 5 project/configuration file(s) and 62 source declaration(s).

Overall architecture

Reference code

SKDemo/SKDemoApp.swift:13 — architecture anchor

@main
struct SKDemoApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .checkCustomerEntitlements()
                .loadProducts()
                .observeErrors()
        }
    }
}

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

Ownership and state

Ownership evidence

SKDemo/SKDemoApp.swift:31 — stored dependency or nearest verified ownership anchor

private struct CustomerEntitlementsViewModifier: ViewModifier {
    private let logger = Logger(subsystem: "SKDemo", category: "CustomerEntitlementsViewModifier")
    // ...
}
Owner Object or state Relationship Mutation authority
CustomerEntitlementsViewModifier Logger (logger) creates and retains Initialized by the owner; the binding is immutable
CustomerEntitlementsViewModifier SKDemoPlusStatus (skDemoPlusStatus) owns wrapper-managed state Owning lexical scope
CustomerEntitlementsViewModifier Set (ownedCars) owns wrapper-managed state Owning lexical scope
ErrorObserverViewModifier Error (error) owns wrapper-managed state Owning lexical scope

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
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. SKDemo/In App Purchase/CustomerEntitlements.swift:14
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. SKDemo/In App Purchase/CustomerEntitlements.swift:35
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. SKDemo/In App Purchase/CustomerEntitlements.swift:52
Detached task Task.detached The source creates a detached task; no specific operating-system thread is established. SKDemo/In App Purchase/CustomerEntitlements.swift:73
Actor isolation actor The cited type is actor-isolated; this does not select a background thread. SKDemoServer/Sources/Server.swift:23

@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

SKDemo/In App Purchase/CustomerEntitlements.swift:14 — representative execution boundary

@MainActor @Observable
public final class CustomerEntitlements {
    // ...
    private var transactionUpdatesTask: Task<Void, any Error>?
    // ...
}

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. SKDemo/In App Purchase/CustomerEntitlements.swift:14
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. SKDemo/SKDemoApp.swift:35
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. SKDemo/Model/Car.swift:9
Source import StoreKit The cited file imports this module; runtime use and architectural role are not inferred. SKDemo/In App Purchase/CustomerEntitlements.swift:10
Source import OSLog The cited file imports this module; runtime use and architectural role are not inferred. SKDemo/In App Purchase/CustomerEntitlements.swift:8
Source import SKDemoServer The cited file imports this module; runtime use and architectural role are not inferred. SKDemo/In App Purchase/CustomerEntitlements.swift:9
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. SKDemo/In App Purchase/SubscriptionGroupID.swift:8
Source import SwiftData The cited file imports this module; runtime use and architectural role are not inferred. SKDemoServer/Sources/Consumable.swift:9

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

SKDemo/SKDemoApp.swift:14 — representative type boundary

@main
struct SKDemoApp: App {
    // ...
            ContentView()
    // ...
}
Type Responsibility Depends on or conforms to
SKDemoApp Application entry and top-level composition App
Store Centralized state or persistence access Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
CarItemStore Centralized state or persistence access Concrete collaborators/imported frameworks
BoostStore Centralized state or persistence access View
CustomProductView User-interface presentation and input forwarding View
SubscriptionStore Centralized state or persistence access View
BoostStore Centralized state or persistence access Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding Concrete collaborators/imported frameworks
FuelStore Centralized state or persistence access Concrete collaborators/imported frameworks

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
logger (SKDemo/In App Purchase/CustomerEntitlements.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.
transactionUpdatesTask (SKDemo/In App Purchase/CustomerEntitlements.swift:17) 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.
statusUpdatesTask (SKDemo/In App Purchase/CustomerEntitlements.swift:18) 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.
shared (SKDemo/In App Purchase/CustomerEntitlements.swift:27) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

SKDemo/In App Purchase/CustomerEntitlements.swift:12 — representative boundary

private let logger = Logger(subsystem: "SKDemo", category: "CustomerEntitlements")

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 SKDemoApp The source’s App suffix makes this role explicit.
Centralized state or persistence access BoostStore, CarItemStore, CarWashStore, FuelStore The source’s Store suffix makes this role explicit.
User-interface presentation and input forwarding ActiveUpfrontView, CommitmentProgressView, ContentView, CustomProductView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Central store SKDemo/View/Miscellaneous/ImageNameConstants.swift:11 A store-named type centralizes feature state or persistence.
Binding-based state propagation SKDemo/View/ContentView.swift:99 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor isolation SKDemoServer/Sources/Server.swift:23 A declared actor creates an explicit isolation boundary; its executor is not described as a background thread.

Naming conventions

  • Types: App: SKDemoApp; Store: BoostStore, CarItemStore, CarWashStore, FuelStore, Store; View: ActiveUpfrontView, CommitmentProgressView, ContentView, CustomProductView, PricingTermsView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: body, checkCurrentUserState, observeEntitlementUpdates, transformOwnedNonConsumables, transformStatuses, checkCustomerEntitlements, loadProducts, observeErrors.
  • Files: SKDemo/SKDemoApp.swift, SKDemo/In App Purchase/Store.swift, SKDemo/View/ContentView.swift, SKDemo/View/Miscellaneous/CarItemStore.swift, SKDemo/View/Stores/BoostStore.swift, SKDemo/View/Stores/SubscriptionStore.swift.

Architecture takeaways

  • SKDemoApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, StoreKit, SKDemoServer, SwiftData 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
SKDemo/SKDemoApp.swift Cited implementation, SKDemoApp, SwiftUI state property wrapper, CustomerEntitlementsViewModifier, ProductLoaderViewModifier, ErrorObserverViewModifier
SKDemo/In App Purchase/CustomerEntitlements.swift Cited implementation, @MainActor, async declaration or closure, Task, Task.detached, @Observable, StoreKit, OSLog, SKDemoServer, CustomerEntitlements, CustomerEntitlementsError
SKDemo/View/Miscellaneous/ImageNameConstants.swift BoostStore, ImageNameConstants, Car, CarItem, ContentView, FuelStore, Garage, PremiumFeatureCard, SubscriptionStore, BillingPlan, OfferCode
SKDemo/View/ContentView.swift Cited implementation, ContentView, GarageButton, ContentGrid, SKDemoPlusSubscriptionOfferViewStyle
SKDemoServer/Sources/Server.swift Server, actor, ServerError
SKDemo/Model/Car.swift SwiftUI, Car
SKDemo/In App Purchase/SubscriptionGroupID.swift Foundation, Feature implementation
SKDemoServer/Sources/Consumable.swift SwiftData, Consumable, CodingKeys
SKDemo/In App Purchase/Store.swift Store, StoreError
SKDemo/View/Miscellaneous/CarItemStore.swift CarItemStore, ContentGrid, StoreHeader, BackgroundGradient
SKDemo/View/Stores/BoostStore.swift BoostStore, CustomProductView, BoostProductViewStyle, BoostProductViewButtonStyle
SKDemo/View/Stores/SubscriptionStore.swift SubscriptionStore, FamilySharingSubscriptionOptionGroupSet, SubscriptionOptionGroup, SKDemoPlusMarketingContent
SKDemo/View/SelectedCarView.swift SelectedCarView, SelectedCarMetricsView
SKDemo/View/SwiftUIMerchandisingView.swift SwiftUIMerchandisingView, MerchandisingViewButtonStyle
SKDemo/Model/SKDemoPlusStatus.swift SKDemoPlusStatus, SKDemoPlusStatusError
SKDemo/View/ActiveUpfrontView.swift ActiveUpfrontView