<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMatrix/init(frame:mode:cellClass:numberOfRows:numberOfColumns:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMatrix(im)initWithFrame:mode:cellClass:numberOfRows:numberOfColumns:"
  },
  "title" : "init(frame:mode:cellClass:numberOfRows:numberOfColumns:)"
}
-->

# init(frame:mode:cellClass:numberOfRows:numberOfColumns:)

Initializes and returns a newly allocated matrix of the specified size using cells of the given class.

```
init(frame frameRect: NSRect, mode: NSMatrix.Mode, cellClass factoryId: AnyClass?, numberOfRows rowsHigh: Int, numberOfColumns colsWide: Int)
```

## Parameters

`frameRect`

The matrix’s frame.

`mode`

The tracking mode for the matrix; this can be one of the modes described in [`NSMatrix.Mode`](/documentation/AppKit/NSMatrix/Mode-swift.enum).

`factoryId`

The class to use for any cells that the matrix creates and uses. This can be obtained by sending a `class` message to the desired subclass of [`NSCell`](/documentation/AppKit/NSCell).

`rowsHigh`

The number of rows in the matrix.

`colsWide`

The number of columns in the matrix.

## Return Value

The initialized instance of [`NSMatrix`](/documentation/AppKit/NSMatrix).

## Discussion

This method is the designated initializer for matrices that add cells by creating instances of an [`NSCell`](/documentation/AppKit/NSCell) subclass.

---

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)