Skip to content
HotLayout Docs

Quickstart for iOS

This page is for an iOS developer. It shows how an app draws a screen that a manager published in HotLayout, using the native reader for iOS: a Swift package that turns a JSON document, a theme and your data into a SwiftUI screen.

Access. The iOS reader is open source and installed with Swift Package Manager from github.com/hotlayout/hotlayout-ios. The React and Flutter packages are open source too; see Quickstart for React and Quickstart for Flutter.

Full reference: iOS reference.

Related pages: index · delivery · data dictionary · theme · localization · compatibility · widgets · quickstart for Android

What you are integrating#

Piece What it is
Document One JSON file: a set of screens built from widgets. Published by the builder as published.json.
Theme One JSON file: the token names the project has and the values behind them.
Data A map your app supplies: values for the paths the document is bound to (user.name, cart.count).
Reader The HotLayout Swift package: it draws the three as a SwiftUI view.

The reader renders documents of contract 9.x, passes the shared tables of cases that the React and Flutter readers pass, and is covered by UI tests. As with every reader, the major version of the contract must match: it draws any 9.x document and no 8.x one (see Compatibility policy); a document that uses a field newer than the reader still opens, and the reader skips the field. Which schema minor each package version reads is in the changelog.

Requirements#

  • iOS 16 or later (the package also builds for macOS 13 so that its tests run with swift test)
  • Swift 5.9 or later
  • no third-party dependencies

Install#

Add the package with Swift Package Manager. In Package.swift:

dependencies: [
    .package(url: "https://github.com/hotlayout/hotlayout-ios", from: "0.5.1"),
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "HotLayout", package: "hotlayout-ios"),
    ]),
]

In Xcode:

  1. Choose File > Add Package Dependencies...
  2. Paste https://github.com/hotlayout/hotlayout-ios into the search field.
  3. Set the dependency rule to Up to Next Major Version, from 0.5.1, and choose Add Package.
  4. Add the HotLayout library to your app target, then import HotLayout.

Draw a screen#

Load the document with the tolerant reader, read the theme, and put HotlayoutScreen where the screen goes:

import HotLayout

let document = try HotlayoutDocument.load(jsonData)   // tolerant read + version gate
let theme = (try? HotlayoutThemeSet.load(themeJSON)) ?? .builtIn

HotlayoutScreen(
    document: document,
    theme: theme,
    data: ["user.name": "Maya", "cart.count": 3],
    locale: Locale.current.identifier,              // the device locale, as is
    entry: "promo",                                 // a named entry point, optional
    onAction: { action, source in
        // The reader opens nothing itself. A standard action arrives checked:
        if let url = StandardActions.url(for: action) { openURL(url) }
    },
    onTrack: { event, source in analytics.log(event.event, event.params) },
    onScreenChange: { shown in print(shown.screenId, shown.cause) }
)

HotlayoutDocument.load(_:) and HotlayoutThemeSet.load(_:) take Data (or a parsed JSONValue) and throw HotlayoutLoadError. Without the view you can also use HotlayoutVersions.checkDocument(_:) (the version rule) and LocaleResolution.resolve(_:available:source:). The global functions loadDocument, loadTheme, checkDocumentVersion and resolveLocale still compile, but are deprecated forwards of these members.

Device language. Locale.current gives the language of the device only if your app declares the languages it is localized for (the app's localizations in the Xcode project, or CFBundleLocalizations in Info.plist). Without that, iOS reports English, and a document that has an Arabic translation is shown in English on an Arabic device. Declare the languages of your documents, or pass Locale.preferredLanguages.first as locale instead.

Where jsonData and themeJSON come from is your choice: your backend after a signed webhook, or the published address of the project. See Delivery options.

What the reader does and does not do#

  • The document is untrusted input. A piece of the wrong shape is skipped and reported through onReport; it is never a crash. A tree deeper than 32 levels is refused.
  • The reader opens nothing by itself. Navigation inside a document (navigate, navigate.back, navigate.section) is done by the reader. openUrl, deeplink, close and the actions of your app go to onAction, and a standard action arrives already checked.
  • Images load only over https: by default. Pass an ImagePolicy to decide yourself, and to give addresses for the asset tokens (logo, banner, placeholder).
  • The locale is the device locale, passed as is; the reader picks the document's language by the contract's rule and mirrors the layout for right-to-left scripts. See Localization.
  • Data stays with you. The reader takes the values you pass in data; it never calls your backend.

Status#

The rules of the contract (versions, data, conditions, text, numbers, dates, plurals, locale, actions and navigation) are in place and pass the shared tables. The widgets of contract 9 are drawn natively (the changelog says up to which minor), including the fixed app bar and bottom zone, input fields (with composed input for CJK keyboards), lists, tabs, progress, carousels, modal layers and motion; behaviour is checked with UI tests on a simulator. Platform limit: glass uses the system blur, so its strength is close to, but not exactly, the contract's blur radius.

Next#