Skip to content
Justin Wojciechowski edited this page Nov 30, 2026 · 14 revisions

Swift Bindings for .NET

Automatically generate C# bindings from compiled Swift libraries.

Swift Bindings reads a compiled framework (.xcframework) and generates idiomatic C# bindings. For Swift libraries, it produces direct P/Invoke code from ABI metadata. For Objective-C libraries, it produces standard ApiDefinition.cs + StructsAndEnums.cs binding definitions from clang AST parsing. No Objective Sharpie, no manual proxy code.

Swift framework (.xcframework)  →  SwiftBindings tool  →  C# bindings + NuGet package

Why This Exists

Apple is moving away from Objective-C. More frameworks ship as Swift-only every year — StoreKit 2, SwiftUI, WeatherKit, App Intents, Swift Charts — and third-party libraries increasingly drop ObjC support entirely.

Without Swift interop, .NET on Apple platforms becomes progressively less capable with each Xcode release.

The existing approaches all require a human to manually translate between Swift and C#, method by method:

Approach Pain Point
Objective Sharpie Requires @objc proxy + bridging headers. Fails on Swift-only APIs. Hasn't kept pace with modern Xcode.
Native Library Interop Requires hand-written C wrappers + C# declarations. Weeks of work for large libraries.
Raw P/Invoke Requires deep Swift ABI knowledge. Not realistic beyond a handful of functions.

Swift Bindings automates the entire process. You point it at a compiled framework and get back a working C# binding.

Quick Example

// Nuke (popular Swift image library), fully generated binding
var pipeline = ImagePipeline.Shared;
var request = new ImageRequest("https://picsum.photos/200/200");
var image = await pipeline.ImageAsync(request);
Console.WriteLine($"Image loaded: {image.Size.Width}x{image.Size.Height}");

No manual wrappers. This is generated C# calling Swift directly.

What It Handles

The generator covers the Swift type system a .NET app actually calls:

  • Classes with ARC, structs (frozen and non-frozen), enums with associated values
  • Protocols with interface generation, proxy classes, and witness table dispatch
  • Generics, async/await, closures, tuples, operators, subscripts, KeyPaths, SIMD vectors
  • SwiftUI Views via automatic UIHostingController bridge generation
  • Idiomatic type conversions (String → string, Array<T> → IReadOnlyList<T>, Optional<T> → T?, UnsafeMutableRawBufferPointer → Span<byte>)

Bindings run on both Apple Silicon (arm64) and Intel (x86_64): pre-built SwiftBindings.Apple.* packages ship both native slices, and for your own bindings the SDK emits an x86_64 slice automatically whenever the source xcframework includes one.

A library with corners we can't bind is meant to yield a partial binding, not a broken one. In standalone generation the tool compiles the C# it emitted before publishing it, withdraws what doesn't compile, and records each withdrawal with a reason — so unsupported Swift shapes are surfaced as documented gaps rather than left to fail in your build. See Known Limitations for what those gaps are.

Validated Against Real Libraries

The compile gate runs against a broad suite of real-world Swift and Objective-C frameworks — Alamofire, Nuke, Kingfisher, Lottie, CryptoSwift, the Stripe family, GRDB, RxSwift, BlinkID, Realm, Stripe3DS2, the Firebase/Google SDK family, SDWebImage, CocoaLumberjack, and more. See Supported Features for details.

This project is a fork of Microsoft's dotnet/runtimelab (feature/swift-bindings branch), substantially extended with protocols, generics, closures, async, SwiftUI bridging, and more. See Architecture for the full history.

Next Steps

Pre-Built Packages

If you just want to use a popular Swift library from .NET without generating bindings yourself, check the swift-dotnet-packages repo. It provides ready-to-use NuGet packages for popular third-party libraries and Apple frameworks — all validated end-to-end on iOS Simulator.

# Third-party libraries
dotnet add package SwiftBindings.Nuke
dotnet add package SwiftBindings.Lottie
dotnet add package SwiftBindings.BlinkID

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

See the Apple Frameworks guide for the full list of supported frameworks, versioning details, and how to bind additional Apple frameworks yourself.

Community

Clone this wiki locally