<!--
{
  "availability" : [
    "macOS: 10.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextContainer/init(containerSize:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextContainer(im)initWithContainerSize:"
  },
  "title" : "init(containerSize:)"
}
-->

# init(containerSize:)

Initializes a text container with a specified bounding rectangle.

```
convenience init(containerSize aContainerSize: NSSize)
```

## Parameters

`aContainerSize`

The size of the text container’s bounding rectangle.

## Return Value

The newly initialized text container.

## Discussion

The new text container must be added to an [`NSLayoutManager`](/documentation/AppKit/NSLayoutManager) object before it can be used. The text container must also have an [`NSTextView`](/documentation/AppKit/NSTextView) object set for text to be displayed. This method is the designated initializer for the `NSTextContainer` class.

---

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)