Warning
The Optimization iOS SDK is in beta. Breaking changes can be published at any time.
The Optimization iOS SDK is a beta Swift Package for native iOS applications. It is part of the Contentful Optimization SDK Suite and runs shared optimization behavior through the local JavaScriptCore bridge while Swift code owns native app concerns such as persistence, networking, lifecycle handling, SwiftUI views, and preview-panel UI.
Table of Contents
- The native Swift package exists under
ContentfulOptimization. - The shared JavaScriptCore adapter package lives under
optimization-js-bridgeand compiles the bridge bundle consumed by Swift. - The native iOS reference app validates current bridge and preview-panel behavior against the shared mock API.
OptimizationConfig.localeis the SDK Experience API and default event locale. Runtime locale changes useOptimizationClient.setLocale(_:). Explicit invalid locale values throw.- Applications query the Contentful Delivery API by content type and slug, using one concrete
application locale, then pass the fetched entry to
OptimizedEntryorresolveOptimizedEntry(...). The native iOS SDK does not provide managed entry fetching. Do not pass all-locale CDA responses fromwithAllLocalesorlocale=*; see Entry personalization and variant resolution. For the broader locale model, see Locale handling in the Optimization SDK Suite. - Treat this surface as beta-stage implementation work. The API, setup flow, and bridge contract are subject to change until a stable native iOS SDK release is declared.
Use this directory when working on the native iOS SDK, SwiftUI integration, JavaScriptCore bridge
handoff, preview-panel behavior, or cross-platform native validation. Application teams that need a
JavaScript mobile integration can start with the
@contentful/optimization-react-native package.
ContentfulOptimization/- Swift Package source, public Swift API, native runtime, resources, and testsoptimization-js-bridge/- shared internal TypeScript bridge compiled into the JavaScriptCore UMD bundle consumed by the Swift PackageCODE_MAP.md- architecture map for the current native iOS implementation
The Swift Package is published to a separate distribution repository,
contentful/optimization.swift, so consumers
can add it by URL (from: "x.y.z") without cloning the monorepo. Publishing is automated by
publish-spm.yaml: on each v* release it builds the
JS bridge (stamping the version into the UMD), assembles the package payload, and pushes a commit
and tag to the distribution repo.
The distribution repo is generated output, like an npm dist/: nobody pushes to it by hand. The UMD
bundle is no longer committed to the monorepo — it is built on demand (and gitignored). Build it
locally before swift build/swift test with pnpm run ios:bridge, or use the convenience scripts
pnpm run ios:build and pnpm run ios:test from the repo root.
- iOS SDK code map - Maintainer architecture map for the native iOS package
- Consent management in the Optimization SDK Suite - Cross-SDK consent policy guidance
- Native bridge architecture - Shared bridge runtime and build notes
- iOS reference app - Native app and XCUITest surface for bridge and preview-panel validation
- React Native SDK - JavaScript mobile-facing SDK
- Core SDK - Shared optimization foundation used through the bridge