yolk

iOS

Yolk provides first-class support for iOS, using the same true zero-copy Swift bridge and JavaScriptCore engine as the macOS target.

Architecture

The iOS implementation is identical to macOS. It uses the Yolk Swift package to manage the JavaScript lifecycle and provide the binary bridge.

JS Engine: JavaScriptCore

Yolk leverages the system-provided JavaScriptCore framework on iOS. This ensures:

  • Zero Binary Size Impact: No need to bundle a heavy JS engine like V8.
  • JIT Performance: High-performance execution on the device.
  • Security: Runs within the standard iOS app sandbox with system-level memory protections.

Data Transfer

iOS uses the YolkBin TLV binary protocol for all communication. Because it shares the same Swift core as macOS, it supports true zero-copy memory sharing via JSObjectMakeArrayBufferWithBytesNoCopy.

Performance

On modern iPhones, the binary bridge can handle 1MB data transfers in under 2ms, making it suitable for:

  • High-frequency sensor data processing.
  • Real-time image manipulation.
  • Complex state synchronization.

Setup

To use Yolk in your iOS app:

  1. Add the Swift Package: Link packages/swift to your Xcode project.
  2. Define a Spec: Create your .spec.ts file.
  3. Run Codegen:
    yolk-codegen playground.spec.ts ./Generated ./src/generated
  4. Implement the Actor:
    actor MyModule: MyModuleProtocol {
        // Implement your native logic here
    }

Example: Reactive UI

In your SwiftUI View, use the generated state to drive your UI reactively:

struct ContentView: View {
    @StateObject var viewModel = PlaygroundViewModel()
 
    var body: some View {
        VStack {
            if let state = viewModel.state {
                Text("Count: \(state.count)")
                Button("Increment") {
                    Task { await viewModel.increment() }
                }
            }
        }
        .onAppear {
            Task { await viewModel.setup() }
        }
    }
}

The iOS Playground in examples/playground/ios provides a complete working implementation including networking and binary performance tests.