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

# init(size:)

Initializes a text container with a specified bounding rectangle.

```
init(size: CGSize)
```

## Parameters

`size`

The size of the text container’s bounding rectangle.

## 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 associated [`NSTextView`](/documentation/AppKit/NSTextView) object 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)