<!--
{
  "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/addColumn(_:named:)-9cb24",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML11MLDataTableV9addColumn_5namedyAA09MLUntypedF0V_SStF"
  },
  "title" : "addColumn(_:named:)"
}
-->

# addColumn(_:named:)

Adds an untyped column to the table.

```
mutating func addColumn(_ newColumn: MLUntypedColumn, named: String)
```

## Parameters

`newColumn`

A column to add to the data table.

`named`

The name of the new column.

## Discussion

Use this method to add an untyped 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.

```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],
]

var bookTable = try MLDataTable(dictionary: data)
```

Then use `MLDataTable/addColumn(_:named:)-9cb24` to add a column to
the table.

```swift
let pagesColumn = MLUntypedColumn([124, 98, 280, 94])
bookTable.addColumn(pagesColumn, named: "Pages")
```

---

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)