Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Running macOS in a virtual machine on Apple silicon

At a glance

Item Summary
Purpose Install and run macOS in a virtual machine using the Virtualization framework.
App architecture A C/Objective-C header, Objective-C, Swift sample bundle with entry-bearing project variants Objective-C, Swift, each leading to Virtualization APIs.
Main patterns Delegate or data-source callbacks
Project style 21 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── Swift/
│   ├── macOSVirtualMachineSampleApp/
│   │   └── AppDelegate.swift
│   ├── InstallationTool/
│   │   └── main.swift
│   └── Common/
│       └── MacOSVirtualMachineDelegate.swift
└── Objective-C/
    ├── InstallationTool/
    │   ├── main.m
    │   └── MacOSRestoreImage.h
    ├── macOSVirtualMachineSampleApp/
    │   ├── main.m
    │   ├── AppDelegate.h
    │   └── AppDelegate.m
    └── Common/
        ├── MacOSVirtualMachineDelegate.h
        ├── MacOSVirtualMachineDelegate.m
        ├── MacOSVirtualMachineConfigurationHelper.h
        └── MacOSVirtualMachineConfigurationHelper.m

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 9 project/configuration file(s) and 10 source declaration(s).

Overall architecture

Reference code

Swift/macOSVirtualMachineSampleApp/AppDelegate.swift:12 — architecture anchor

@main
class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
}

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

Swift/macOSVirtualMachineSampleApp/AppDelegate.swift:15 — stored dependency or nearest verified ownership anchor

    @IBOutlet var window: NSWindow!

    @IBOutlet weak var virtualMachineView: VZVirtualMachineView!

    private var virtualMachineResponder: MacOSVirtualMachineDelegate?

    private var virtualMachine: VZVirtualMachine!
Owner Object or state Relationship Mutation authority
AppDelegate NSWindow (window) stores or receives App/module collaborators
AppDelegate VZVirtualMachineView (virtualMachineView) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere
AppDelegate MacOSVirtualMachineDelegate (virtualMachineResponder) stores or receives Owning lexical scope
AppDelegate VZVirtualMachine (virtualMachine) stores or receives 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.

Class and protocol design

Swift/macOSVirtualMachineSampleApp/AppDelegate.swift:13 — representative type boundary

class AppDelegate: NSObject, NSApplicationDelegate {
    // ...
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
MacOSVirtualMachineDelegate Receives callback-driven events NSObject, VZVirtualMachineDelegate
MacOSVirtualMachineDelegate Receives callback-driven events NSObject, VZVirtualMachineDelegate
MacOSVirtualMachineConfigurationHelper Defines a feature-specific type boundary NSObject
MacOSRestoreImage Defines a feature-specific type boundary NSObject
MacOSVirtualMachineInstaller Defines a feature-specific type boundary NSObject
MacOSVirtualMachineConfigurationHelper Represents a feature value or composable behavior Concrete collaborators/imported frameworks
MacOSRestoreImage Owns feature behavior and collaborator lifecycle NSObject
MacOSVirtualMachineInstaller Owns feature behavior and collaborator lifecycle NSObject

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
virtualMachineView (Objective-C/macOSVirtualMachineSampleApp/AppDelegate.m:19) implementation Visibility follows header/implementation and language linkage rules. Inference: keep the declaration in the Objective-C implementation boundary.
window (Objective-C/macOSVirtualMachineSampleApp/AppDelegate.m:21) implementation Visibility follows header/implementation and language linkage rules. Inference: keep the declaration in the Objective-C implementation boundary.
downloadObserver (Swift/InstallationTool/MacOSRestoreImage.swift:14) 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.
download (Swift/InstallationTool/MacOSRestoreImage.swift:18) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

Objective-C/macOSVirtualMachineSampleApp/AppDelegate.m:19 — representative boundary

@interface AppDelegate ()
// ...
@property (weak) IBOutlet VZVirtualMachineView *virtualMachineView;
// ...
@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
Receives callback-driven events AppDelegate, MacOSVirtualMachineDelegate The source’s Delegate suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks Objective-C/Common/MacOSVirtualMachineDelegate.h:13 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Delegate: AppDelegate, MacOSVirtualMachineDelegate.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: createMacPlaform, createVirtualMachine, startVirtualMachine, resumeVirtualMachine, restoreVirtualMachine, applicationDidFinishLaunching, applicationShouldTerminateAfterLastWindowClosed, saveVirtualMachine.
  • Files: Swift/macOSVirtualMachineSampleApp/AppDelegate.swift, Objective-C/macOSVirtualMachineSampleApp/AppDelegate.h, Objective-C/macOSVirtualMachineSampleApp/AppDelegate.m, Objective-C/Common/MacOSVirtualMachineDelegate.h, Objective-C/Common/MacOSVirtualMachineDelegate.m, Swift/Common/MacOSVirtualMachineDelegate.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Virtualization, Cocoa, AppKit, sys 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
Swift/macOSVirtualMachineSampleApp/AppDelegate.swift AppDelegate
Objective-C/InstallationTool/main.m Feature implementation
Objective-C/macOSVirtualMachineSampleApp/main.m Feature implementation
Swift/InstallationTool/main.swift Feature implementation
Objective-C/macOSVirtualMachineSampleApp/AppDelegate.h AppDelegate
Objective-C/macOSVirtualMachineSampleApp/AppDelegate.m AppDelegate, AppDelegate
Objective-C/Common/MacOSVirtualMachineDelegate.h MacOSVirtualMachineDelegate
Objective-C/Common/MacOSVirtualMachineDelegate.m MacOSVirtualMachineDelegate
Swift/Common/MacOSVirtualMachineDelegate.swift MacOSVirtualMachineDelegate
Objective-C/Common/MacOSVirtualMachineConfigurationHelper.h MacOSVirtualMachineConfigurationHelper