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

# addRow()

Adds a new row of cells below the last row.

```
func addRow()
```

## Discussion

New cells are created as needed with [`makeCell(atRow:column:)`](/documentation/AppKit/NSMatrix/makeCell(atRow:column:)). This method raises an `NSRangeException` if there are 0 rows or 0 columns. 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:)), then new cells are created only if they are needed. This fact allows you to grow and shrink an 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)