iOS / SwiftUI
Overview
Section titled “Overview”The ios() builder renders Swift code for SwiftUI. Output includes type-safe Color, CGFloat, Font.Weight, and more. Doc comments are generated from $description.
import { ios } from 'dispersa'Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
| name | string | — | Unique output identifier |
| file | string or function | — | Output path (supports {*context*} interpolation for modifiers) |
| preset | ’standalone' | 'standalone’ | Output preset |
| accessLevel | ’public’ | ‘internal' | 'public’ | Swift access level |
| structure | ’enum’ | ‘grouped' | 'enum’ | Code structure |
| enumName | string | ’DesignTokens’ | Custom enum name (enum mode) |
| extensionNamespace | string | ’DesignTokens’ | Namespace enum name (grouped mode) |
| colorSpace | ’sRGB’ | ‘displayP3' | 'sRGB’ | Color space for Color() |
| swiftVersion | ’5.9’ | ‘6.0' | '5.9’ | Swift version target |
| indent | number | 4 | Spaces per indentation level |
| frozen | boolean | false | @frozen annotation for ABI stability |
| transforms | Transform[] | — | Per-output transforms |
| filters | Filter[] | — | Per-output filters |
Example Output
Section titled “Example Output”public enum Tokens { public enum Color { public enum Brand { /// Primary brand color public static let primary = Color(.sRGB, red: 0, green: 0.4, blue: 0.8) } } public enum Spacing { public static let medium: CGFloat = 16 }}Token Type Mapping
Section titled “Token Type Mapping”| Token Type | Swift Type |
|---|---|
| color | Color |
| dimension | CGFloat |
| fontFamily | String |
| fontWeight | Font.Weight |
| duration | TimeInterval |
| number | Double |
| shadow | ShadowStyle |
| cubicBezier | UnitCurve |
| typography | TypographyStyle |
| border | BorderStyle |
| gradient | Gradient |
Display P3 Color Space
Section titled “Display P3 Color Space”Use displayP3 for wider gamut on capable devices:
ios({ name: 'tokens', file: 'Tokens.swift', colorSpace: 'displayP3',})Note: avoid using colorToHex() with displayP3 — hex colors are limited to the sRGB gamut, so the transform would negate the wider P3 gamut advantage.
Swift 6.0 Compatibility
Section titled “Swift 6.0 Compatibility”When swiftVersion is '6.0', static properties use nonisolated(unsafe) for Swift 6 concurrency:
ios({ name: 'tokens', file: 'Tokens.swift', swiftVersion: '6.0',})Doc Comments
Section titled “Doc Comments”Token $description values are emitted as Swift doc comments:
/// Primary brand color used for CTAspublic static let primary = Color(.sRGB, red: 0, green: 0.4, blue: 0.8) Android / Jetpack Compose Generate Kotlin code for Jetpack Compose with type-safe design tokens.