# to-swift

## Interface

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

## Options

<table data-full-width="true"><thead><tr><th width="226">Parameter</th><th width="100">Required</th><th>Type</th><th width="285">Default</th><th width="293">Description</th></tr></thead><tbody><tr><td><code>tokenNameTemplate</code></td><td><code>false</code></td><td>string</td><td><code>{{path}}{{token}}{{mode}}</code></td><td>The template the parser follows to name your tokens.<br><br>You can use the <code>path</code> of your tokens, their <code>token</code> name, and their respective <code>mode</code>.</td></tr><tr><td><code>scopeName</code></td><td><code>false</code></td><td>string</td><td><code>DesignTokens</code></td><td>The name of the parent class which contains all classes for all your token types.</td></tr></tbody></table>

## Basic usage

{% tabs %}
{% tab title="Input" %}
{% code lineNumbers="true" %}

```json
{
  "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"
          }
        }
      }
    }
  }
}
```

{% endcode %}
{% endtab %}

{% tab title="Config" %}
{% code title=".specifyrc.json" lineNumbers="true" %}

```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"
          }
        }
      ]
    }
  ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Output" %}
{% code title="output/tokens.swift" lineNumbers="true" %}

```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
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.specifyapp.com/reference/parsers/to-swift.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
