# SwiftBrowser

Run SwiftUI apps in the browser, so you can build and iterate on iOS apps
without a Mac for most of the day.

An app's source imports `SwiftUI` and compiles unchanged for both iOS and the
browser. On Apple platforms it uses Apple's SwiftUI. In the browser it compiles
to WebAssembly against the API-compatible shim in `Sources/SwiftUI`, which turns
the view tree into render ops that a small TypeScript renderer draws inside an
iPhone frame, or full screen on a phone.

```sh
npx @swiftbrowser/cli doctor --install          # Swift 6.4's wasm SDK and wasm-opt
npx @swiftbrowser/cli check ~/Projects/MyApp    # what the app imports, and a fast compile against the shim
npx @swiftbrowser/cli dev ~/Projects/MyApp      # http://localhost:5173, rebuilds on save
npx @swiftbrowser/cli build ~/Projects/MyApp    # ./dist: a static site to deploy anywhere
```

Eighteen of the nineteen Hacking with SwiftUI projects run from their Xcode
projects without a change, and so does a trimmed version of Apple's Food Truck
sample (`Examples/FoodTruck`).

## Documentation

For app developers:

- [Getting started](https://swiftbrowser-docs.pages.dev/getting-started): from an Xcode project to a
  deployed site.
- [CLI reference](https://swiftbrowser-docs.pages.dev/cli): commands, `swiftbrowser.json`,
  Foundation, frameworks, Core ML, Swift packages.
- [Compatibility](https://swiftbrowser-docs.pages.dev/compatibility): the SwiftUI, SwiftData and framework
  APIs the browser build supports.
- [`@swiftbrowser/xcodeproj`](https://swiftbrowser-docs.pages.dev/xcodeproj): the Xcode
  project reader, usable on its own.

How it works:

- [Architecture](https://swiftbrowser-docs.pages.dev/architecture) and the
  [ops protocol](https://swiftbrowser-docs.pages.dev/ops-protocol) between Swift and the renderer.
- [The web renderer](https://swiftbrowser-docs.pages.dev/web-renderer) and its dev server.
- [History](https://swiftbrowser-docs.pages.dev/history): what each development phase added.

Working on SwiftBrowser itself: [CONTRIBUTING.md](https://swiftbrowser-docs.pages.dev/contributing) (local
development, CI, deploying the examples, releasing to npm, repository layout).

All of it is also published at <https://swiftbrowser-docs.pages.dev>
([`DocsSite/`](https://github.com/noya-app/SwiftBrowser/blob/main/DocsSite/README.md)), where every page, or the whole site at
once, can be copied as Markdown.

## Packages

| Package | What it is |
|---|---|
| [`@swiftbrowser/cli`](https://swiftbrowser-docs.pages.dev/cli) | `doctor`, `check`, `dev` and `build` for an Xcode project or a folder of Swift sources |
| [`@swiftbrowser/web`](https://swiftbrowser-docs.pages.dev/web-renderer) | the renderer, the dev server and the static site build |
| [`@swiftbrowser/xcodeproj`](https://swiftbrowser-docs.pages.dev/xcodeproj) | a dependency-free `project.pbxproj` reader |
| [`@swiftbrowser/swift`](https://github.com/noya-app/SwiftBrowser/blob/main/packages/swift/README.md) | the Swift package (the SwiftUI shim, Charts, SwiftData, FoundationBridge and the framework stand-ins) the CLI builds against |
