Skip to content

Apple Frameworks

Justin Wojciechowski edited this page Nov 30, 2026 · 16 revisions

Apple Frameworks

Swift Bindings can generate C# bindings directly from Apple's built-in frameworks — no xcframework file needed. This means you can call APIs like StoreKit 2, WeatherKit, CryptoKit, and MusicKit from .NET, even though Apple ships them as Swift-only with no Objective-C bridge.

Pre-built NuGet packages for all supported Apple frameworks are available on NuGet.org. The source for all framework bindings is in swift-dotnet-packages. Installing a package is all you need:

dotnet add package SwiftBindings.Apple.CryptoKit
dotnet add package SwiftBindings.Apple.StoreKit2
dotnet add package SwiftBindings.Apple.WeatherKit

Naming. Each Apple framework ships as SwiftBindings.Apple.{Framework} — the Apple. prefix groups the platform packages and keeps them distinct from third-party library packages like SwiftBindings.Nuke or SwiftBindings.Lottie. The C# namespace inside the package matches the Swift module (CryptoKit, WeatherKit, …) — except for StoreKit2, which uses an explicit suffix to avoid collision with the Microsoft.iOS StoreKit namespace. All Apple framework packages share a single SwiftBindings.Apple supplement (referenced transitively) for Swift-only value types that have no ObjC bridge (e.g., Foundation.AttributedString / LanguageIdentifier, Foundation.Locale.Language, CryptoKit signature types) — see the versioning section.


Supported Frameworks

Framework Platforms NuGet Package
ActivityKit (Live Activities) iOS SwiftBindings.Apple.ActivityKit — see Live Activities
CryptoKit iOS, macOS, Mac Catalyst, tvOS SwiftBindings.Apple.CryptoKit
FamilyControls iOS SwiftBindings.Apple.FamilyControls
LiveCommunicationKit iOS, macOS, Mac Catalyst SwiftBindings.Apple.LiveCommunicationKit
Matter iOS, macOS, Mac Catalyst SwiftBindings.Apple.Matter
MatterSupport iOS, macOS, Mac Catalyst SwiftBindings.Apple.MatterSupport
MusicKit iOS, macOS, Mac Catalyst, tvOS SwiftBindings.Apple.MusicKit
MusicUnderstanding iOS 27, tvOS 27 SwiftBindings.Apple.MusicUnderstanding (needs Xcode 27.2 or later)
ProximityReader iOS, Mac Catalyst SwiftBindings.Apple.ProximityReader
RealityFoundation iOS SwiftBindings.Apple.RealityFoundation
RealityKit iOS SwiftBindings.Apple.RealityKit
RoomPlan iOS SwiftBindings.Apple.RoomPlan
StoreKit 2 iOS, macOS, Mac Catalyst, tvOS SwiftBindings.Apple.StoreKit2
TipKit iOS, macOS, Mac Catalyst, tvOS SwiftBindings.Apple.TipKit
Translation iOS SwiftBindings.Apple.Translation
WeatherKit iOS, macOS, Mac Catalyst, tvOS SwiftBindings.Apple.WeatherKit
WorkoutKit iOS, macOS, Mac Catalyst SwiftBindings.Apple.WorkoutKit

Frameworks Apple ships that are intentionally NOT in this list. AuthenticationServices, CoreSpotlight, and SoundAnalysis are already fully bound by Microsoft.iOS — use those instead. AppIntents is intentionally not published: its data-modeling types (AppEntity, EntityQuery, EntityProperty) do compile through the generator, but the product surface — authoring an @AppIntent and the build-time metadata extraction (appintentsmetadataprocessor) that Siri / Shortcuts / Spotlight read — requires Swift source a C# app never emits, so a binding hands you data types nothing in the OS will act on. Expose App Intents from a small Swift companion target instead. ActivityKit (Live Activities / Dynamic Island) does ship (SwiftBindings.Apple.ActivityKit), but with one design constraint worth understanding: its entry point Activity<Attributes> requires a type conforming to ActivityAttributes, which refines Codable & Hashable — conformances the Swift compiler synthesizes from the type's stored properties at compile time, so a C# type the Swift compiler never saw can never serve as Attributes. The binding works around this by shipping one fixed, Swift-defined attributes type that carries your dynamic data as JSON, which covers the overwhelming majority of Live Activities; genuinely distinct per-app attributes structs remain a Swift-companion-target job. Full walkthrough — including the ~30-line SwiftUI widget — on the Live Activities page. SwiftData, Observation, Swift Charts, WidgetKit, and SwiftUI itself are macro-driven or SwiftUI-bound and don't have a callable surface from C#.

Platform availability matches what Apple ships. Some frameworks like RealityKit and RoomPlan are iOS-only because Apple doesn't provide them on other platforms. If Apple expands availability in a future SDK, updated bindings will follow.

Update cadence. The pre-built SwiftBindings.Apple.* packages are regenerated and published on each new Apple SDK train (new Xcode releases). They track the validation-libraries.json "apple-framework" entries and the Apple supplement package (SwiftBindings.Apple) carries the SDK version (e.g. 26.2.x). See the packages repo and build/validation-libraries.json for the exact current set and how to request additional frameworks.


Using Apple Framework Bindings

1. Install the NuGet package

dotnet add package SwiftBindings.Apple.WeatherKit --version 26.2.8

2. Write C# code

using WeatherKit;

// Access the shared weather service singleton
var service = WeatherService.Shared;

// Async methods return Task<T> — use await naturally
var attribution = await service.GetAttributionAsync();

// Enums have proper cases with round-trip support
var raw = MoonPhase.WaxingCrescent.ToRawValue();          // "waxingCrescent"
var back = MoonPhaseExtensions.FromRawValue(raw);          // MoonPhase.WaxingCrescent

// Tagged unions (Swift enums with associated values) expose a .Tag property
var condition = WeatherCondition.Clear;
if (condition.Tag == WeatherCondition.CaseTag.Clear) { /* ... */ }
using StoreKit2;

// Static properties work as expected
bool canPay = AppStore.CanMakePayments;
Guid? deviceId = AppStore.DeviceVerificationID;

// Nested type singletons mirror Swift's namespacing
var production = AppStore.Environment.Production;
var sandbox = AppStore.Environment.Sandbox;
Console.WriteLine($"Production: {production.RawValue}");

// Error types expose description methods
var desc = Product.PurchaseError.InvalidQuantity.GetErrorDescription();
using TipKit;

// Constructors with parameters
var limit = new Tips.DonationLimit(3);
Console.WriteLine($"Max: {limit.MaximumCount}");  // 3

// Factory methods
var fiveMinutes = Tips.DonationTimeRange.Minutes(5);
var oneWeek = Tips.DonationTimeRange.Weeks(1);

The bindings are idiomatic C# — async methods return Task<T>, enums have proper cases, singletons are static properties, and memory management is handled automatically via SafeHandle and ARC bridging.

Swift AsyncSequence returns (e.g., Transaction.CurrentEntitlements, Transaction.Updates) lower to IAsyncEnumerable<T>, so await foreach works:

using StoreKit2;

await foreach (var entitlement in Transaction.CurrentEntitlements)
{
    // process verified transaction
}

3. Build and run

Apple framework bindings work on every runtime an app can use:

  • .NET 10: Mono on iOS, tvOS, and Mac Catalyst, with CoreCLR on macOS. Publish with PublishAot to use NativeAOT.
  • .NET 11: CoreCLR on every platform, using the interpreter in Debug and ReadyToRun in Release on iOS, tvOS, and Mac Catalyst. Publish with PublishAot to use NativeAOT.

The SwiftBindings.Apple.* packages built for 11.0.0 carry 3 copies, labeled net10.0-<platform>26.0, net10.0-<platform>27.2, and net11.0-<platform>27.2. NuGet restores the newest copy the app's target framework allows. A .NET 10 app on any Xcode 26 release (such as 26.5) gets the 26.0 copy, as does a .NET 10 app on the Xcode 27.0 or 27.1 workload. MusicUnderstanding requires Xcode 27.2 or later, so it includes only the 2 27.2 copies. A single package version works in .NET 10 and .NET 11 apps, and the 27.2 copies are generated against the iOS 27 SDK. The earlier 26.2.x packages include only a .NET 10 copy, and a .NET 11 app skips the build check that guards Swift calls on the interpreter. Before you use one of those in a .NET 11 app, read Choosing .NET and Xcode.

dotnet build
dotnet run

Keep the app on a versionless TFM (net10.0-ios). An app TFM pinned to 26.2 fails on .NET 10 + Xcode 27.2 with NETSDK1140, because that workload doesn't install the 26.2 platform.


How It Works

Unlike third-party library bindings that start from a pre-built .xcframework, Apple framework bindings work directly with the SDK installed alongside Xcode. The build process is fully automated by the SwiftBindings.Sdk MSBuild SDK:

  1. SDK resolution — The SDK maps your project's Target Framework Moniker (TFM) to the correct Xcode platform SDK. For example, net10.0-ios26.2 resolves to the iphoneos / iphonesimulator SDK paths via xcrun.

  2. ABI extraction — Apple's swift-api-digester tool reads the framework's .swiftinterface file (the stable ABI contract Apple ships with each SDK) and produces a JSON description of every public type, method, and property.

  3. Binding generation — The Swift Bindings generator processes the ABI JSON and produces C# bindings (P/Invoke declarations, type wrappers, marshalling code) and a Swift wrapper file that exposes @_cdecl entry points for any API that needs bridging (async methods, protocol dispatch, closure parameters, etc.).

  4. Wrapper compilation — The Swift wrapper is compiled against the Apple SDK into a small .xcframework that ships alongside the C# bindings.

  5. Multi-slice packaging — For iOS and tvOS packages, the SDK builds device and simulator wrapper slices and merges them into a single xcframework, so one NuGet package works for both development (simulator) and release (device) builds. The simulator slices are universal (arm64 + x86_64), and the macOS / Mac Catalyst slices carry both arm64 and x86_64 — so Intel Macs and x64 simulators resolve a matching native slice with no consumer configuration. See CPU Architectures for the one Mac Catalyst x64 caveat (it defaults to the Mono interpreter).

The end result is a NuGet package that contains the C# bindings and the compiled Swift wrapper. The Apple framework itself is already on the device — it doesn't need to be bundled.

No xcframework input needed. This is the key difference from third-party library bindings. Apple frameworks are part of the OS, so the SDK reads their ABI definition directly from Xcode's SDK and links against the system framework at runtime.


Versioning

Apple framework NuGet packages follow a version scheme that mirrors the Apple SDK they were compiled against:

{AppleSDKVersion}.0

For example, a package built against the iOS 26.2 SDK has version 26.2.x. This makes it immediately clear which OS features are included — if Apple adds new APIs in iOS 26.3, a new 26.3.0 package will expose them. The .0/.1 revision tracks bindings-side fixes against the same Apple SDK.

What the version tells you

Package Version Built Against Minimum Deployment Target
26.2.8 iOS/macOS/tvOS 26.2 SDK iOS 15.0 / macOS 12.0 / Mac Catalyst 15.0 / tvOS 15.0

The minimum deployment target is the oldest OS version your app can run on. The SDK version determines which APIs are available in the bindings. APIs introduced after the minimum deployment target are still present in the bindings, but may not be available at runtime on older OS versions. Use .NET's platform guards to check availability:

if (OperatingSystem.IsIOSVersionAtLeast(17))
{
    // Call APIs introduced in iOS 17+
}

The generated bindings include [SupportedOSPlatform] attributes where applicable, so the .NET analyzer (CA1416) will warn you at build time if you call a newer API without a guard. This now covers the Objective-C surface of a framework too: Apple's API_AVAILABLE / API_DEPRECATED / API_UNAVAILABLE annotations flow through to [SupportedOSPlatform] / [ObsoletedOSPlatform] / [UnsupportedOSPlatform], so CA1416 flags an out-of-range ObjC call the same way it does a Swift one.

For a Swift-generated API this goes one step further: if an OS-gated member is actually called at runtime on a version that doesn't support it, the generated wrapper throws a catchable PlatformNotSupportedException rather than crashing the process — so a missing guard fails loudly and recoverably. Objective-C members carry the availability attributes for the CA1416 build-time check but have no runtime guard, so rely on the analyzer for those. See Troubleshooting — PlatformNotSupportedException.

Backwards compatibility

  • Broad deployment support — Your app can deploy to iOS 15.0, macOS 12.0, Mac Catalyst 15.0, or tvOS 15.0 and later. The bindings use the modern SDK for generation, but the minimum deployment target defaults to these floors, matching Apple's typical support window.

  • Upgrading packages — When a new Apple SDK ships (e.g., 26.3), updated packages will be published. Upgrading is a NuGet version bump — the C# API surface grows additively, so existing code continues to compile.

  • SDK version pinning — Each binding package is tied to the SDK version it was generated from. If you need bindings for a specific SDK version, reference that exact package version.


Multi-Platform Support

Apple framework bindings use .NET's Target Framework Moniker (TFM) system to support multiple platforms from a single codebase. Each platform has its own TFM:

TFM Platform Notes
net10.0-ios iPhone and iPad Includes Simulator (dev) and Device (release)
net10.0-macos macOS desktop Native macOS apps
net10.0-maccatalyst Mac Catalyst iPad apps running on Mac
net10.0-tvos Apple TV tvOS apps

Keep app TFMs versionless, as above: the workload then builds the app against the platform version its own Xcode supports. A 26.2 app TFM fails with NETSDK1140 on the .NET 10 workload for Xcode 27.2.

CPU architectures. Each package ships both arm64 (Apple Silicon) and x86_64 (Intel) native slices, so the same TFM works on both Mac generations and on Intel simulators with no extra configuration. The one caveat: net10.0-maccatalyst apps on Intel default to the Mono interpreter. See CPU Architectures.

How it works in practice

When a framework supports multiple platforms (like CryptoKit on iOS, macOS, Mac Catalyst, and tvOS), the NuGet package contains bindings for all of them. Your app's TFM determines which platform's bindings are used:

<!-- Your app project -->
<PropertyGroup>
  <TargetFramework>net10.0-ios</TargetFramework>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="SwiftBindings.Apple.CryptoKit" Version="26.2.8" />
</ItemGroup>

The same C# code works across platforms — you write it once, and the correct platform-specific native interop is selected at build time.

Multi-platform apps

If your app targets multiple Apple platforms, reference the same package from each platform project. The package resolves the correct bindings automatically:

<!-- Shared across all platform targets -->
<ItemGroup>
  <PackageReference Include="SwiftBindings.Apple.WeatherKit" Version="26.2.8" />
</ItemGroup>

Binding Apple Frameworks Yourself

The pre-built NuGet packages cover the frameworks listed above, but you can also bind additional Apple frameworks yourself using the SwiftBindings.Sdk. This is useful if you need a framework we haven't published yet, or if you want to target a different SDK version. Coverage will depend on how much of the framework's API surface uses supported Swift features — check the generated binding-report.json to see what was bound and what was skipped.

1. Create a binding project

dotnet new swift-binding -n MyFramework --appleFramework HealthKit

Add --framework net11.0 for a .NET 11 binding. The template writes the SDK version it was installed with and a SwiftAppleFrameworkTarget item:

<Project Sdk="SwiftBindings.Sdk/{version}">
  <PropertyGroup>
    <TargetFrameworks>net10.0-ios;net10.0-macos;net10.0-maccatalyst;net10.0-tvos</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <SwiftAppleFrameworkTarget Include="HealthKit" />
  </ItemGroup>
</Project>

Keep only the platforms you need.

The SwiftAppleFrameworkTarget item tells the SDK to resolve the framework from the Xcode SDK instead of looking for a local xcframework file. The Include value is the framework's module name (e.g., HealthKit, CoreML, ARKit).

Cross-framework dependencies are auto-injected. The SDK reads the framework's .swiftinterface import lines and adds matching <PackageReference Include="SwiftBindings.Apple.<Module>" …> entries for any module that resolves against the bundled Apple-framework registry. This flows into both restore and pack, so a downstream framework that imports (say) RealityFoundation gets the right NuGet edge automatically. Opt out with <SwiftAutoDetectAppleFrameworkDependencies>false</SwiftAutoDetectAppleFrameworkDependencies>.

2. Pick the target frameworks for your toolchain

Which TFM to use depends on your toolchain. The framework's API is read from the active Xcode's SDK, so use a platform version that matches it and that your .NET workload installs:

Pairing TFMs to use
.NET 10 + Xcode 26.3 net10.0-ios26.2, net10.0-macos26.2, …
.NET 10 + Xcode 27.2 net10.0-ios27.2, net10.0-macos27.2, … (26.2 isn't installed by this workload and fails with NETSDK1140)
.NET 11 + Xcode 27.2 net11.0-ios27.2, net11.0-macos27.2, … (the only platform version the .NET 11 workloads build)

dotnet new swift-binding -n MyFramework --appleFramework HealthKit (add --framework net11.0 for .NET 11) writes a project with versionless TFMs for all four platforms. A package labelled 27.2 can only be restored by apps whose workload has the 27.2 platform (on .NET 10 + Xcode 26.3 the restore fails with NU1202). See Choosing .NET and Xcode.

On .NET 10 + Xcode 27.2, replace the versionless TFMs with 27.2 ones, for example net10.0-ios27.2;net10.0-macos27.2;net10.0-maccatalyst27.2;net10.0-tvos27.2. On .NET 11 the versionless TFMs already mean 27.2.

A framework that first ships in the iOS 27 SDK (MusicUnderstanding, for example) is iOS 27.0+ in every member. Either raise the app's minimum OS:

<SupportedOSPlatformVersion>27.0</SupportedOSPlatformVersion>

or guard each entry point with if (OperatingSystem.IsIOSVersionAtLeast(27)) { ... }. Without one of the two, every call warns CA1416, and on an older OS the call throws PlatformNotSupportedException before reaching Swift.

3. Build

dotnet build

The SDK handles everything — finding the framework in the Xcode SDK, extracting the ABI, generating bindings, and compiling the wrapper.

4. Package (optional)

dotnet pack

This produces a NuGet package with both device and simulator slices, ready for distribution.

Configuration options

The SwiftAppleFrameworkTarget item supports optional metadata for advanced scenarios:

<SwiftAppleFrameworkTarget Include="StoreKit">
  <!-- Override the C# namespace (default: framework module name) -->
  <NamespacePattern>StoreKit2</NamespacePattern>
  <!-- Override minimum deployment version (default: iOS 15.0 / macOS 12.0) -->
  <MinDeploymentVersion>16.0</MinDeploymentVersion>
</SwiftAppleFrameworkTarget>

Differences from Third-Party Library Bindings

Apple Frameworks Third-Party Libraries
Input Framework name (resolved from Xcode SDK) .xcframework file
ABI source .swiftinterface via swift-api-digester Binary ABI metadata from xcframework
Framework bundling Not needed (framework is part of the OS) Bundled into the app via NuGet
Versioning Tied to Apple SDK version (e.g., 26.2.8) Library's own version
Project item <SwiftAppleFrameworkTarget> <SwiftFramework> (or auto-discovered)

Referencing pure-Objective-C Apple frameworks (e.g., Matter)

A handful of Apple frameworks are pure Objective-C with no .swiftinterface — Apple ships them as Swift via the ObjC bridge. The generator recognizes these and routes type references through their .NET bindings instead of treating them as Swift modules. The list covers everything Microsoft.iOS already binds (UIKit, Foundation, CoreBluetooth, Photos, MapKit, HealthKit, …) plus Matter, which Microsoft.iOS does not bind.

The Matter case shows up when binding MatterSupport (Swift), whose public surface refers to Matter.MTRSetupPayload and the WiFi enums MTRNetworkCommissioningWiFiBand / MTRNetworkCommissioningWiFiSecurity. The generator auto-binds Matter.framework end-to-end through its ObjC pipeline, so cross-module Matter.* references from MatterSupport resolve against the auto-generated binding — no hand-written ApiDefinition.cs / StructsAndEnums.cs needed. Both are pre-built; just install them from NuGet:

dotnet add package SwiftBindings.Apple.Matter
dotnet add package SwiftBindings.Apple.MatterSupport

The SwiftBindings.Apple.MatterSupport package already pulls in SwiftBindings.Apple.Matter transitively, so adding MatterSupport alone is enough if you only need its API; reference Matter explicitly when your own code calls MTR… types directly.

If a future Microsoft.iOS workload ships a Matter binding, drop the standalone binding and reference the workload binding instead — Matter.MTR… will resolve through whichever assembly is in scope.


Next Steps

Clone this wiki locally