How it's generated

How SwiftUI's declarations in Xcode become components, modifiers, values and these docs.

Almost none of the API is written by hand. A generator reads the SwiftUI that ships with Xcode and writes the library from it. This page explains what that means, and why it matters to you.

1. Read from the SDK

Every public SwiftUI declaration is read straight from the iOS SDK: views, initializers, modifiers, value types and protocols. Each one keeps its full signature:

  • Parameter labels, types and default values
  • Generic constraints, closures and @ViewBuilder content
  • Which protocols a type conforms to, and what each modifier applies to
  • The iOS version it first appeared in, and any deprecations
  • Apple's documentation comment

None of this is typed in by hand, and no list of components is kept anywhere. If a type is a public SwiftUI View, the generator finds it.

2. Decide how each API should look in React

Next, each declaration gets a React shape based on what it is.

SwiftUIReact
A view and its initializersA component, with a prop for each parameter
A modifier and its overloadsA method on compose(), with one form for each overload
An enum, struct or styleA typed value, often a string like 'leading' or 'title'
A Binding parameterA prop that takes useBinding
A @ViewBuilder closureReact children, or a prop that takes React content
An action closureA JavaScript callback with typed arguments

Some APIs don't fit neatly. A modifier might take an unusual closure, or a generic that can't cross into JavaScript. Those are marked as needing an adapter, which is a small piece of hand-written native code, and the generator writes everything around it. An API that can't be represented safely is left out, so nothing ships half-working.

3. Write the code

From that design, the generator writes everything the package needs, for every API:

  • TypeScript: components, the compose() methods, value types and their definitions
  • Swift: the code that builds each view and applies each modifier through SwiftUI's typed API
  • C++ and Objective-C++: the Fabric component specs and the native glue that mounts each view
  • Documentation: the reference, from the same declarations

4. Prove it builds

The generated Swift is compiled against the real SDK. Anything that fails to compile is excluded and reported, so what ships always builds. Generation is also deterministic: the same SDK always produces the same files, byte for byte.

What this means for you

  • New APIs arrive quickly. When a new Xcode adds SwiftUI APIs, they appear after the next generation, with nobody writing wrappers by hand.
  • The reference is exact. Each page comes from the same declaration as the code, so the props, types and availability you read are what you get.
  • The package stays small. You install the generated code and the native runtime. The generator and its data aren't in the package, and your app never needs them.

Read Principles for the rules behind these decisions.