---
title: "addColumn(_:named:)"
framework: createml
role: symbol
role_heading: Instance Method
path: "createml/mldatatable/addcolumn(_:named:)-kkbw"
---

# addColumn(_:named:)

Adds a data column to the table.

## Declaration

```swift
mutating func addColumn<Element>(_ newColumn: MLDataColumn<Element>, named: String) where Element : MLDataValueConvertible
```

## Parameters

- `newColumn`: A column to add to the data table.
- `named`: The name of the new column.

## Discussion

Discussion Use this method to add a data column to a data table. important: The number of elements in the column must equal the number of rows in the data table. Otherwise, the data table will be invalidated. As an example, start with a data table variable. 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], ]

var bookTable = try MLDataTable(dictionary: data) Then use addColumn(_:named:) to add a column to the table. let pagesColumn = MLDataColumn([124, 98, 280, 94]) bookTable.addColumn(pagesColumn, named: "Pages")
