---
title: "replaceTextContainer(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextview/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.

## Declaration

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

## Parameters

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

## See Also

### Related Documentation

- [init(frame:textContainer:)](appkit/nstextview/init(frame:textcontainer:).md)

### Accessing text system objects

- [stronglyReferencesTextStorage](appkit/nstextview/stronglyreferencestextstorage.md)
- [fieldEditor()](appkit/nstextview/fieldeditor().md)
- [textContainer](appkit/nstextview/textcontainer.md)
- [textContainerInset](appkit/nstextview/textcontainerinset.md)
- [textContainerOrigin](appkit/nstextview/textcontainerorigin.md)
- [invalidateTextContainerOrigin()](appkit/nstextview/invalidatetextcontainerorigin().md)
- [textLayoutManager](appkit/nstextview/textlayoutmanager.md)
- [layoutManager](appkit/nstextview/layoutmanager.md)
- [textContentStorage](appkit/nstextview/textcontentstorage.md)
- [textStorage](appkit/nstextview/textstorage.md)
