Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Mixing Languages in an Xcode project

At a glance

Item Summary
Purpose Use C++ APIs in Swift – and Swift APIs in C++ – in a single framework target, and consume the framework’s APIs in a separate app target.
App architecture A C++, C/Objective-C header, Swift sample with the source-visible chain Swift_and_Cplusplus_mixed_FibonacciFrameworkAppFibonacciViewSwiftUI APIs.
Main patterns No named application pattern supported by the extracted structure
Project style 5 scanned source file(s) across C++, C/Objective-C header, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── Swift-and-Cplusplus-mixed-FibonacciFramework/
│   ├── Swift_and_Cplusplus_mixed_FibonacciFrameworkApp.swift
│   ├── FibonacciView.swift
│   └── Swift_and_Cplusplus_mixed_FibonacciFramework.entitlements
├── Fibonacci/
│   ├── Fibonacci.swift
│   ├── Fibonacci.h
│   └── FibonacciCplusplus.cpp
├── Configuration/
│   └── SampleCode.xcconfig
└── Swift-and-Cplusplus-mixed-FibonacciFramework.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C++, C/Objective-C header, Swift.
  • The verified tree contains 4 project/configuration file(s) and 3 source declaration(s).

Overall architecture

Reference code

Swift-and-Cplusplus-mixed-FibonacciFramework/Swift_and_Cplusplus_mixed_FibonacciFrameworkApp.swift:10 — architecture anchor

@main
struct SwiftCplusplusFibonacciFrameworkApp: App {
    var body: some Scene {
        WindowGroup {
            FibonacciView()
        }
    }
}

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

Ownership and state

Ownership evidence

Fibonacci/Fibonacci.swift:9 — stored dependency or nearest verified ownership anchor

public struct FibonacciCalculator {
    private let printInvocation: Bool
    // ...
}
Owner Object or state Relationship Mutation authority
FibonacciCalculator Bool (printInvocation) owns value state 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

Swift-and-Cplusplus-mixed-FibonacciFramework/Swift_and_Cplusplus_mixed_FibonacciFrameworkApp.swift:11 — representative type boundary

struct SwiftCplusplusFibonacciFrameworkApp: App {
    var body: some Scene {
        WindowGroup {
            FibonacciView()
        }
    }
}
Type Responsibility Depends on or conforms to
SwiftCplusplusFibonacciFrameworkApp Application entry and top-level composition App
FibonacciView User-interface presentation and input forwarding View
FibonacciCalculator Represents a feature value or composable behavior 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
printInvocation (Fibonacci/Fibonacci.swift:9) 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.
Fibonacci (Fibonacci/Fibonacci.swift:11) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
fibonacci (Fibonacci/Fibonacci.swift:15) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
FibonacciView (Swift-and-Cplusplus-mixed-FibonacciFramework/FibonacciView.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

Fibonacci/Fibonacci.swift:9 — representative boundary

    private let printInvocation: Bool
    
    public init(printInvocation: Bool) {
        self.printInvocation = printInvocation
    }

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 SwiftCplusplusFibonacciFrameworkApp The source’s App suffix makes this role explicit.
User-interface presentation and input forwarding FibonacciView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
No named application pattern Swift-and-Cplusplus-mixed-FibonacciFramework/Swift_and_Cplusplus_mixed_FibonacciFrameworkApp.swift:10 The verified source directly composes concrete framework types; this document avoids forcing a pattern name.

Naming conventions

  • Types: App: SwiftCplusplusFibonacciFrameworkApp; View: FibonacciView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: fibonacci.
  • Files: Swift-and-Cplusplus-mixed-FibonacciFramework/FibonacciView.swift.

Architecture takeaways

  • Swift_and_Cplusplus_mixed_FibonacciFrameworkApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches Fibonacci, SwiftUI, iostream 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-and-Cplusplus-mixed-FibonacciFramework/Swift_and_Cplusplus_mixed_FibonacciFrameworkApp.swift SwiftCplusplusFibonacciFrameworkApp
Swift-and-Cplusplus-mixed-FibonacciFramework/FibonacciView.swift FibonacciView, ContentView_Previews
Fibonacci/Fibonacci.swift FibonacciCalculator
Fibonacci/Fibonacci.h Feature implementation
Fibonacci/FibonacciCplusplus.cpp Feature implementation