Skip to content

pantoken / platforms/swift/src / toSwift

Function: toSwift()

toSwift(tokens, options): Promise<string>

Experimental

Emit Swift for an explicit token IR.

Parameters

tokens

readonly Token[]

options

GenerateSwiftOptions

Returns

Promise<string>

The path of the written Swift file.

Examples

Emit a specific theme's IR

ts
import { toSwift } from "@pantoken/swift";
import { byTheme } from "@pantoken/tokens";

const file = await toSwift(byTheme("canvas"), { outDir: "./Sources/Tokens" });
// writes Tokens.swift (class PanTokens { … })

Dark mode with a custom class name and an asset catalog

ts
import { toSwift } from "@pantoken/swift";
import { byTheme } from "@pantoken/tokens";

await toSwift(byTheme("rebrand"), {
  outDir: "./Sources/Tokens",
  mode: "dark",
  className: "InstUITokens",
  icons: ["add", "check"], // also emits Icons.xcassets
});