<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateMLComponents",
  "identifier" : "/documentation/CreateMLComponents/OneHotEncoder/Transformer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML Components",
      "CreateMLComponents"
    ],
    "preciseIdentifier" : "s:18CreateMLComponents13OneHotEncoderV11TransformerV"
  },
  "title" : "OneHotEncoder.Transformer"
}
-->

# OneHotEncoder.Transformer

A transformer that encodes a category as an array of integers.

```
struct Transformer
```

## Topics

### Creating a transformer

[`init(categories: Set<Category?>)`](/documentation/CreateMLComponents/OneHotEncoder/Transformer/init(categories:))

Creates a one-hot encoder.

### Getting the categories

[`var categories: Set<Category?>`](/documentation/CreateMLComponents/OneHotEncoder/Transformer/categories)

Unique values to encode

[`func category(at: Int) -> Category?`](/documentation/CreateMLComponents/OneHotEncoder/Transformer/category(at:))

Retrieves the category at the one-hot encoding index.

### Performing the transformation

[`func applied<S>(S, eventHandler: EventHandler?) throws -> [[Int]]`](/documentation/CreateMLComponents/OneHotEncoder/Transformer/applied(_:eventHandler:))

Performs a one-hot encoding on a sequence of inputs.

[`func applied(to: Category?, eventHandler: EventHandler?) throws -> [Int]`](/documentation/CreateMLComponents/OneHotEncoder/Transformer/applied(to:eventHandler:))

Performs a one-hot encoding on a single input.

### Default Implementations

[Decodable Implementations](/documentation/CreateMLComponents/OneHotEncoder/Transformer/Decodable-Implementations)

[Encodable Implementations](/documentation/CreateMLComponents/OneHotEncoder/Transformer/Encodable-Implementations)

## Relationships

### Conforms To

[`Escapable`](/documentation/Swift/Escapable)

[`Decodable`](/documentation/Swift/Decodable)

[`Transformer`](/documentation/CreateMLComponents/Transformer)

[`Sendable`](/documentation/Swift/Sendable)

[`Copyable`](/documentation/Swift/Copyable)

[`Encodable`](/documentation/Swift/Encodable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)