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

# replaceTextContainer(_:)

Replaces the text container for the group of text system objects containing the receiver, keeping the association between the receiver and its layout manager intact.

```
func replaceTextContainer(_ newContainer: NSTextContainer)
```

## Parameters

`newContainer`

The new text container. This method raises `NSInvalidArgumentException` if `aTextContainer` is `nil`.

## See Also

[`-  initWithFrame:textContainer:`](/documentation/AppKit/NSTextView/init(frame:textContainer:))

Initializes a text view.



---

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)