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

Offering, completing, and restoring in-app purchases

At a glance

Item Summary
Purpose Fetch, display, purchase, validate, and finish transactions in your app.
App architecture A C/Objective-C header, Objective-C, Swift sample bundle with entry-bearing project variants Objective-C, Swift, each leading to StoreKit APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks
Project style 75 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── Objective-C/
│   ├── iOS/
│   │   ├── main.m
│   │   └── ParentViewController.m
│   ├── macOS/
│   │   ├── main.m
│   │   ├── AppDelegate.m
│   │   └── MainViewController.m
│   ├── tvOS/
│   │   ├── main.m
│   │   └── TabBarViewController.m
│   └── Common/
│       ├── StoreManager.m
│       └── StoreObserver.m
└── Swift/
    ├── Common/
    │   └── AppProtocols.swift
    ├── iOS/
    │   └── ParentViewController.swift
    └── tvOS/
        └── TabBarViewController.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, Objective-C, Swift.
  • The verified tree contains 27 project/configuration file(s) and 62 source declaration(s).

Overall architecture

Reference code

Objective-C/iOS/main.m:11 — architecture anchor

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

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

Objective-C/Common/StoreManager.m:12 — stored dependency or nearest verified ownership anchor

@property (strong) NSMutableArray *availableProducts;

/// Keeps track of all invalid product identifiers.
@property (strong) NSMutableArray *invalidProductIdentifiers;

/// Keeps a strong reference to the product request.
@property (strong) SKProductsRequest *productRequest;
Owner Object or state Relationship Mutation authority
StoreManager NSMutableArray (availableProducts) retains or copies an assigned value Owning Objective-C implementation
StoreManager NSMutableArray (invalidProductIdentifiers) retains or copies an assigned value Owning Objective-C implementation
StoreManager SKProductsRequest (productRequest) retains or copies an assigned value Owning Objective-C implementation
StoreObserver BOOL (hasRestorablePurchases) stores or receives Owning Objective-C implementation

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

Swift/Common/AppProtocols.swift:12 — representative type boundary

protocol DiscloseView {
    func show()
    func hide()
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate, NSUserInterfaceValidations
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
DiscloseView Defines a capability or collaboration contract Concrete collaborators/imported frameworks
StoreManagerDelegate Defines a capability or collaboration contract AnyObject
StoreObserverDelegate Defines a capability or collaboration contract AnyObject
SettingsDelegate Defines a capability or collaboration contract AnyObject
IAPTableViewDataSource Defines a capability or collaboration contract NSObject
ParentViewController View lifecycle, callbacks, and feature coordination UIViewController
TabBarViewController View lifecycle, callbacks, and feature coordination UITabBarController

The source explicitly defines local protocol relationships: BaseViewControllerIAPTableViewDataSource, NSViewDiscloseView, UIViewDiscloseView, UIBarItemEnableItem, ParentViewControllerStoreManagerDelegate, ParentViewControllerStoreObserverDelegate.

Access control

Symbol Access Verified effect Likely rationale
data (Objective-C/Common/BaseViewController.h:12) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
name (Objective-C/Common/Section.h:12) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
elements (Objective-C/Common/Section.h:15) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
message (Objective-C/Common/StoreManager.h:15) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.

Reference code

Objective-C/Common/BaseViewController.h:12 — representative boundary

@interface BaseViewController : UITableViewController <IAPTableViewDataSource>
@property (strong) NSMutableArray *data;
@end

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
View lifecycle, callbacks, and feature coordination BaseViewController, MainViewController, MessagesViewController, ParentViewController The source’s Controller suffix makes this role explicit.
Supplies data through a callback contract IAPTableViewDataSource The source’s DataSource suffix makes this role explicit.
Receives callback-driven events AppDelegate, SettingsDelegate, StoreManagerDelegate, StoreObserverDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination StoreManager The source’s Manager suffix makes this role explicit.
Observes and relays feature changes StoreObserver The source’s Observer suffix makes this role explicit.
User-interface presentation and input forwarding DiscloseView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization Objective-C/Common/BaseViewController.h:11 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction Objective-C/Common/BaseViewController.h:11 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks Objective-C/Common/BaseViewController.h:11 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: BaseViewController, MainViewController, MessagesViewController, ParentViewController, PrimaryViewController; DataSource: IAPTableViewDataSource; Delegate: AppDelegate, SettingsDelegate, StoreManagerDelegate, StoreObserverDelegate; Manager: StoreManager; Observer: StoreObserver; View: DiscloseView.
  • Protocols: DiscloseView, StoreManagerDelegate, StoreObserverDelegate, SettingsDelegate, IAPTableViewDataSource, EnableItem.
  • Methods: sharedInstance, init, startProductRequestWithIdentifiers, fetchProductsMatchingIdentifiers, productsRequest, request, titleMatchingIdentifier, titleMatchingPaymentTransaction.
  • Files: Objective-C/Common/StoreManager.m, Objective-C/Common/StoreObserver.m, Objective-C/iOS/ParentViewController.m, Objective-C/macOS/AppDelegate.m, Objective-C/macOS/MainViewController.m, Objective-C/tvOS/TabBarViewController.m.

Architecture takeaways

  • main is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches StoreKit, UIKit, Cocoa 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
Objective-C/iOS/main.m Feature implementation
Objective-C/macOS/main.m Feature implementation
Objective-C/tvOS/main.m Feature implementation
Objective-C/Common/StoreManager.m StoreManager, StoreManager
Objective-C/Common/StoreObserver.m StoreObserver, StoreObserver
Objective-C/iOS/ParentViewController.m ParentViewController, ParentViewController
Objective-C/macOS/AppDelegate.m AppDelegate, AppDelegate
Objective-C/macOS/MainViewController.m MainViewController, MainViewController
Objective-C/tvOS/TabBarViewController.m TabBarViewController, TabBarViewController
Swift/Common/AppProtocols.swift DiscloseView, EnableItem, StoreManagerDelegate, StoreObserverDelegate, SettingsDelegate