https://github.com/tanvesh01/effect-swiftui.git, select Exact Version: 0.3.0, and add the EffectSwiftUI product to your app target..package(url: "https://github.com/tanvesh01/effect-swiftui.git", exact: "0.3.0") to the package dependencies and .product(name: "EffectSwiftUI", package: "effect-swiftui") to your target dependencies. The Swift module is EffectSwiftUI in both cases.package.json, install the adapter and the two packages the component imports. This command targets the 0.3.0 npm release; if it isn't available in your registry yet, use the source checkout below.1bun add --exact effect-swiftui@0.3.0 effect@4.1.7 'https://pkg.pr.new/Effect-TS/ui/@effect/ui@82a1750'
@effect/ui is a commit-pinned upstream preview; a fresh install needs access to pkg.pr.new. Keep the resulting lockfile. Create src/counter.ts:import "effect-swiftui/runtime" import * as UiSchema from "@effect/ui/UiSchema" import { component, start } from "effect-swiftui" import * as Schema from "effect/Schema" const Message = UiSchema.TaggedEnum({ Count: {} }) const Counter = component({ name: "Counter", model: Schema.Struct({ count: Schema.Number }), message: Message }).make({ init: () => ({ count: 0 }), update: { Count: ({ model }) => ({ count: model.count + 1 }) }, view: (h, model) => h.button .prop("title", `Count: ${model.count}`) .on("press", Message.Count()) }) start(Counter, {})
1bun build src/counter.ts --target=browser --format=iife --conditions=production --minify --outfile=dist/counter.js
dist/counter.js to your Xcode app target’s Copy Bundle Resources. Rebuild it whenever you change the TypeScript. Bun is not required on the user's device, and the browser build target does not provide a DOM.import EffectSwiftUI import Foundation import SwiftUI @main struct CounterApp: App { private let script = Result { guard let url = Bundle.main.url(forResource: "counter", withExtension: "js") else { throw CocoaError(.fileNoSuchFile) } return try String(contentsOf: url, encoding: .utf8) } var body: some Scene { WindowGroup { switch script { case .success(let source): EffectSwiftUISurface(script: source) case .failure(let error): Text("Cannot load counter.js: \(error.localizedDescription)") } } } }
1234git clone --branch 0.3.0 --depth 1 https://github.com/tanvesh01/effect-swiftui.git cd effect-swiftui bun install --frozen-lockfile --ignore-scripts bun run demo
src/counter.ts, set step: 5 in init and run bun run demo again. The first click now takes the count from 0 to 5.