---
title: "setTextContainer(_:forGlyphRange:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nslayoutmanager/settextcontainer(_:forglyphrange:)"
---

# setTextContainer(_:forGlyphRange:)

Associates a text container with the specified range of glyphs.

## Declaration

```swift
func setTextContainer(_ container: NSTextContainer, forGlyphRange glyphRange: NSRange)
```

## Parameters

- `container`: The text container to set.
- `glyphRange`: The range of glyphs to lay out.

## Discussion

Discussion The layout within the container is specified with the setLineFragmentRect(_:forGlyphRange:usedRect:) and setLocation(_:forStartOfGlyphRange:) methods. This method is used by the layout mechanism and should be invoked only during typesetting, in almost all cases only by the typesetter. For example, a custom typesetter might invoke it.

## See Also

### Managing the text containers

- [textContainers](appkit/nslayoutmanager/textcontainers.md)
- [addTextContainer(_:)](appkit/nslayoutmanager/addtextcontainer(_:).md)
- [insertTextContainer(_:at:)](appkit/nslayoutmanager/inserttextcontainer(_:at:).md)
- [removeTextContainer(at:)](appkit/nslayoutmanager/removetextcontainer(at:).md)
- [textContainerChangedGeometry(_:)](appkit/nslayoutmanager/textcontainerchangedgeometry(_:).md)
- [textContainerChangedTextView(_:)](appkit/nslayoutmanager/textcontainerchangedtextview(_:).md)
- [textContainer(forGlyphAt:effectiveRange:)](appkit/nslayoutmanager/textcontainer(forglyphat:effectiverange:).md)
- [textContainer(forGlyphAt:effectiveRange:withoutAdditionalLayout:)](appkit/nslayoutmanager/textcontainer(forglyphat:effectiverange:withoutadditionallayout:).md)
- [usedRect(for:)](appkit/nslayoutmanager/usedrect(for:).md)
