Skip to main content
The Metabind iOS SDK lets you render server-driven UI in your Swift applications. Build dynamic experiences that update instantly without app store releases.

View on GitHub

Source code, issues, and releases.

Requirements

RequirementVersion
Xcode15.0 or later
iOS17.0 or later
macOS14.0 or later
Swift5.9 or later

Installation

Add the Metabind SDK to your project using Swift Package Manager.
  1. Open your project in Xcode
  2. Go to File → Add Package Dependencies
  3. Enter the repository URL:
https://github.com/yapstudios/metabind-apple
  1. Select the version and add to your target

Quick start

1. Initialize the client

Create a MetabindClient with your API credentials from the Metabind dashboard:
import SwiftUI
import Metabind

@main
struct MyApp: App {

    @State var client = MetabindClient(
        url: URL(string: "https://api.metabind.ai/graphql")!,
        ws: URL(string: "wss://ws-api.metabind.ai")!,
        apiKey: "your-api-key",
        organizationId: "your-org-id",
        projectId: "your-project-id"
    )

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .environment(client)
    }
}

2. Display content

Use MetabindView to render content by its ID:
struct ContentView: View {

    var body: some View {
        MetabindView(contentId: "your-content-id")
    }
}

3. Handle actions

Listen for actions triggered by user interactions:
MetabindView(contentId: "your-content-id")
    .onMetabindAction { action in
        switch action.name {
        case "metabind.content":
            // Navigate to another content page
            if let contentId = action.props["contentId"] as? String {
                navigateTo(contentId)
            }
        case "custom.action":
            // Handle your custom actions
            handleCustomAction(action.props)
        default:
            break
        }
    }

Core concepts

MetabindClient

The client manages the connection to Metabind’s API and handles:
  • Authentication — API key validation and request signing
  • Content fetching — GraphQL queries for content and components
  • Real-time updates — WebSocket subscriptions for live content changes
  • Caching — Local caching of fetched content and components
Inject the client into the SwiftUI environment so all views can access it:
.environment(client)

MetabindView

MetabindView is the primary way to display content. It automatically:
  • Fetches the content and its required components
  • Renders the UI based on your design system
  • Subscribes to real-time updates when content changes
  • Handles loading and error states
MetabindView(contentId: "content-id")

Actions

Actions are events triggered by user interactions with your content. The SDK provides the onMetabindAction modifier to handle these:
ActionDescription
metabind.contentNavigate to another content page
metabind.urlOpen an external URL
metabind.dismissDismiss the current view
Custom actionsYour own defined actions
For apps with multiple content pages, integrate with SwiftUI’s navigation system:
struct ContentView: View {

    @State private var path = NavigationPath()

    private enum Destination: Hashable {
        case content(id: String)
    }

    var body: some View {
        NavigationStack(path: $path) {
            MetabindView(contentId: "home")
                .onMetabindAction { action in
                    if action.name == "metabind.content",
                       let contentId = action.props["contentId"] as? String
                    {
                        path.append(Destination.content(id: contentId))
                    }
                }
                .navigationDestination(for: Destination.self) { destination in
                    switch destination {
                    case .content(let id):
                        MetabindView(contentId: id)
                    }
                }
        }
    }
}

Platform support

The SDK supports all Apple platforms with SwiftUI:
PlatformMinimum Version
iOS17.0
macOS14.0
tvOS17.0
watchOS10.0
visionOS1.0

Next steps