Swift Academy · Lesson

Binary Targets and XCFrameworks

Distributing closed-source code as XCFramework and consuming as a binary target.

Lesson 3 of 413 steps

Binary Targets and XCFrameworks is a free Swift Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 4 lessons in total.

What is a Binary Target?

A binary target distributes a precompiled framework (XCFramework) instead of source code, protecting proprietary implementations.

// Package.swift:
.binaryTarget(
  name: "ClosedSDK",
  path: "Frameworks/ClosedSDK.xcframework"
)

What is an XCFramework?

An XCFramework bundles multiple platform slices (iOS, macOS, simulator) into a single distributable archive.

// XCFramework structure:
// ClosedSDK.xcframework/
// ├── ios-arm64/
// ├── ios-arm64_x86_64-simulator/
// └── macos-arm64_x86_64/

Creating an XCFramework

Build archives for each platform and combine them with xcodebuild -create-xcframework.

xcodebuild archive -scheme MySDK -destination "generic/platform=iOS" -archivePath ios.xcarchive SKIP_INSTALL=NO
xcodebuild archive -scheme MySDK -destination "generic/platform=iOS Simulator" -archivePath sim.xcarchive SKIP_INSTALL=NO
xcodebuild -create-xcframework \
  -framework ios.xcarchive/Products/Library/Frameworks/MySDK.framework \
  -framework sim.xcarchive/Products/Library/Frameworks/MySDK.framework \
  -output MySDK.xcframework

Remote Binary Target with Checksum

Reference a remotely hosted XCFramework zip with its SHA-256 checksum for integrity verification.

.binaryTarget(
  name: "ClosedSDK",
  url: "https://cdn.example.com/ClosedSDK-1.0.0.xcframework.zip",
  checksum: "abc123def456..."
)

Computing the Checksum

Use swift package compute-checksum to generate the SHA-256 checksum for the zip file.

swift package compute-checksum ClosedSDK-1.0.0.xcframework.zip
# Outputs: abc123def456...

Using Binary Targets in App

Add the binary target as a dependency in another target's dependencies list, just like a source target.

.target(
  name: "MyApp",
  dependencies: [
    .target(name: "ClosedSDK")
  ]
)

Importing the XCFramework

Import the module in Swift code exactly like any other import.

import ClosedSDK

let result = ClosedSDK.ProcessData(input: myData)

Privacy Manifest Requirements

Apple requires XCFrameworks distributed on the App Store to include a PrivacyInfo.xcprivacy manifest listing used APIs.

// ClosedSDK.xcframework/
// ├── ios-arm64/ClosedSDK.framework/
// │   └── PrivacyInfo.xcprivacy
// └── ...

Debug vs Release Builds

When consuming an XCFramework, you cannot step through source in the debugger — you only see symbols. dSYM files can be bundled for crash symbolication.

// Distribute dSYMs alongside XCFramework for crash reporting:
// ClosedSDK-1.0.0.xcframework.zip
// ClosedSDK-1.0.0.dSYM.zip

Versioning XCFrameworks

Use semantic versioning in the filename and SPM package version to ensure consumers can pin compatible versions.

// ClosedSDK-1.2.0.xcframework.zip
// In Package.swift:
// .package(url: "...", from: "1.2.0")

XCFramework vs Source Packages

Use XCFramework for proprietary code, large precompiled SDKs, or C/C++ wrappers. Use source packages for open-source Swift code.

// XCFramework: proprietary analytics SDK, vendor-provided libraries
// Source: open-source Alamofire, SwiftUI components

Quick Check

Why do you include a checksum when declaring a remote binary target in Package.swift?

Lesson Recap

Binary targets distribute precompiled XCFrameworks without source code. Build with xcodebuild -create-xcframework, host the zip, compute its checksum with swift package compute-checksum, and declare it in Package.swift. Include a PrivacyInfo.xcprivacy for App Store submission.

Free to start

Learn Swift with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
122
Lessons
409

Frequently Asked Questions

Is the “Binary Targets and XCFrameworks” lesson free?

Yes — any 3 lessons of the Swift Academy learning path, including “Binary Targets and XCFrameworks”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 4 lessons in total.

What will I learn in “Binary Targets and XCFrameworks”?

Distributing closed-source code as XCFramework and consuming as a binary target. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Swift Academy?

No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Binary Targets and XCFrameworks” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Swift Academy lesson?

Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Package.swift: Targets, Products and Dependencies
  2. Local Packages and Feature Modules
  3. Binary Targets and XCFrameworks
  4. Versioning, Resolving Conflicts and Swift Plugins
← Back to Swift Academy