<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMatrix/addColumn()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMatrix(im)addColumn"
  },
  "title" : "addColumn()"
}
-->

# addColumn()

Adds a new column of cells to the right of the last column.

```
func addColumn()
```

## Discussion

This method raises an `NSRangeException` if there are 0 rows or 0 columns. This method creates new cells as needed with [`makeCell(atRow:column:)`](/documentation/AppKit/NSMatrix/makeCell(atRow:column:)). Use [`renewRows(_:columns:)`](/documentation/AppKit/NSMatrix/renewRows(_:columns:)) to add new cells to an empty matrix.

If the number of rows or columns in the receiver has been changed with [`renewRows(_:columns:)`](/documentation/AppKit/NSMatrix/renewRows(_:columns:)), new cells are created only if they are needed. This fact allows you to grow and shrink an [`NSMatrix`](/documentation/AppKit/NSMatrix) without repeatedly creating and freeing the cells.

This method redraws the receiver. Your code may need to send [`sizeToCells()`](/documentation/AppKit/NSMatrix/sizeToCells()) after sending this method to resize the receiver to fit the newly added cells.

## See Also

[`var prototype: NSCell?`](/documentation/AppKit/NSMatrix/prototype)

The prototype cell that’s copied whenever the matrix creates a new cell.

[`var cellClass: AnyClass`](/documentation/AppKit/NSMatrix/cellClass)

The subclass of [`NSCell`](/documentation/AppKit/NSCell) that the matrix uses when creating new (empty) cells.



---

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)