Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Interface
  • Options
  • Basic usage

Was this helpful?

Export as PDF
  1. Reference
  2. Parsers

to-swift

This parser helps you generate design tokens as Swift classes.

Interface

interface parser {
  name: 'to-swift';
  output: {
    type: 'file';
    filePath: string;
  };
  options?: {
    tokenNameTemplate?: string;
    scopeName?: string;
  }
}

Options

Parameter
Required
Type
Default
Description

tokenNameTemplate

false

string

{{path}}{{token}}{{mode}}

The template the parser follows to name your tokens. You can use the path of your tokens, their token name, and their respective mode.

scopeName

false

string

DesignTokens

The name of the parent class which contains all classes for all your token types.

Basic usage

{
  "colors": {
    "$collection": {
      "$modes": [
        "light",
        "dark"
      ]
    },
    "aliases": {
      "border": {
        "active": {
          "$type": "color",
          "$value": {
            "dark": {
              "$alias": "colors.core.label.blue-base",
              "$mode": "dark"
            },
            "light": {
              "$alias": "colors.core.label.blue-base",
              "$mode": "light"
            }
          }
        }
      }
    },
    "core": {
      "label": {
        "blue-base": {
          "$type": "color",
          "$value": {
            "dark": {
              "model": "rgb",
              "red": 96,
              "green": 168,
              "blue": 250,
              "alpha": 1
            },
            "light": {
              "model": "rgb",
              "red": 17,
              "green": 125,
              "blue": 249,
              "alpha": 1
            }
          }
        },
        "blue-lighter": {
          "$type": "color",
          "$value": {
            "dark": {
              "model": "rgb",
              "red": 41,
              "green": 52,
              "blue": 67,
              "alpha": 1
            },
            "light": {
              "model": "rgb",
              "red": 219,
              "green": 236,
              "blue": 254,
              "alpha": 1
            }
          }
        }
      }
    }
  },
  "dimensions": {
    "$collection": {
      "$modes": [
        "desktop",
        "mobile"
      ]
    },
    "base": {
      "dimension-01": {
        "$type": "dimension",
        "$value": {
          "mobile": {
            "value": 2,
            "unit": "px"
          },
          "desktop": {
            "value": 4,
            "unit": "px"
          }
        }
      },
      "dimension-02": {
        "$type": "dimension",
        "$value": {
          "mobile": {
            "value": 4,
            "unit": "px"
          },
          "desktop": {
            "value": 8,
            "unit": "px"
          }
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "To Swift",
      "parsers": [
        {
          "name": "to-swift",
          "output": {
            "type": "file",
            "filePath": "public/tokens.swift"
          }
        }
      ]
    }
  ]
}
output/tokens.swift
import SwiftUI

class DesignTokens {
  class Color_ {
    static let colorsCoreLabelBlue_baseDark = Color(red: 0.37647, green: 0.65882, blue: 0.98039, opacity: 1)
    static let colorsCoreLabelBlue_baseLight = Color(red: 0.06667, green: 0.49020, blue: 0.97647, opacity: 1)
    static let colorsAliasesBorderActiveDark = Color(red: 0.37647, green: 0.65882, blue: 0.98039, opacity: 1)
    static let colorsAliasesBorderActiveLight = Color(red: 0.06667, green: 0.49020, blue: 0.97647, opacity: 1)
    static let colorsCoreLabelBlue_lighterDark = Color(red: 0.16078, green: 0.20392, blue: 0.26275, opacity: 1)
    static let colorsCoreLabelBlue_lighterLight = Color(red: 0.85882, green: 0.92549, blue: 0.99608, opacity: 1)
  }

  class Dimension {
    static let dimensionsBaseDimension_01Desktop = 4
    static let dimensionsBaseDimension_01Mobile = 2
    static let dimensionsBaseDimension_02Desktop = 8
    static let dimensionsBaseDimension_02Mobile = 4
  }
}
Previousto-style-dictionaryNextto-tailwind

Last updated 1 year ago

Was this helpful?