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

# setTextContainer(_:forGlyphRange:)

Associates a text container with the specified range of glyphs.

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

## Parameters

`container`

The text container to set.

`glyphRange`

The range of glyphs to lay out.

## Discussion

The layout within the container is specified with the [`setLineFragmentRect(_:forGlyphRange:usedRect:)`](/documentation/AppKit/NSLayoutManager/setLineFragmentRect(_:forGlyphRange:usedRect:)) and [`setLocation(_:forStartOfGlyphRange:)`](/documentation/AppKit/NSLayoutManager/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.

---

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)