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

# insertRow(_:with:)

Inserts a new row of cells before the specified row, using the given cells.

```
func insertRow(_ row: Int, with newCells: [NSCell]?)
```

## Parameters

`row`

The location at which to insert the new row.

`newCells`

An array of objects to use when filling the new row, starting with the object at index 0. Each object in `newCells` should be an instance of [`NSCell`](/documentation/AppKit/NSCell) or one of its subclasses (usually [`NSActionCell`](/documentation/AppKit/NSActionCell)).

## Discussion

If `row` is greater than the number of rows in the receiver, enough rows are created to expand the receiver to be `row` rows high. `newCells` should either be empty or contain a sufficient number of cells to fill each new row. If `newCells` is `nil` or an array with no elements, the call is equivalent to calling [`insertRow(_:)`](/documentation/AppKit/NSMatrix/insertRow(_:)). Extra cells are ignored, unless the matrix is empty. In that case, a matrix is created with one row and enough columns for all the elements of `newCells`.

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.

---

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)