<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLDataTable/init(dictionary:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML11MLDataTableV10dictionaryACSDySSAA0C16ValueConvertible_pG_tKcfc"
  },
  "title" : "init(dictionary:)"
}
-->

# init(dictionary:)

Creates a data table from a dictionary of column names and data values.

```
init(dictionary: [String : any MLDataValueConvertible]) throws
```

## Parameters

`dictionary`

The dictionary of each column name and its associated data values.

## Discussion

Use this initializer to create a data table from an in-memory
<doc://com.apple.documentation/documentation/Swift/Dictionary>.

![A table of information about a book. Columns named “Title”, “Author”,](images/com.apple.createml/MLDataTable-init(dictionary:)-1@2x.png)

For example, to create a data table as shown above, first create a
dictionary.

```swift
let data: [String: MLDataValueConvertible] = [
    "Title": ["Alice in Wonderland", "Hamlet", "Treasure Island", "Peter Pan"],
    "Author": ["Lewis Carroll", "William Shakespeare", "Robert L. Stevenson", "J. M. Barrie"],
    "Pages": [124, 98, 280, 94],
    "Genre": ["Fantasy", "Drama", "Adventure", "Fantasy"]
]
```

Then, use [`init(dictionary:)`](/documentation/CreateML/MLDataTable/init(dictionary:)) to create a data table from
the dictionary.

```swift
let bookTable = try MLDataTable(dictionary: data)
```

The keys of the dictionary become the column names, and the value of
each key becomes the element(s) of the corresponding column in the data
table.

---

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)