<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.6.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextInput/attributedSubstringFromRange:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextInput(im)attributedSubstringFromRange:"
  },
  "title" : "attributedSubstringFromRange:"
}
-->

# attributedSubstringFromRange:

Returns an attributed string derived from the given range in the receiver’s text storage.

```
- (NSAttributedString *) attributedSubstringFromRange:(NSRange) range;
```

## Parameters

`range`

The range in the text storage from which to create the returned string.

## Return Value

The string created from the given range.

## Discussion

This method allows input mangers to query any range in text storage.

An implementation of this method should be prepared for `theRange` to be out-of-bounds. For example, the InkWell text input service can ask for the contents of the text input client that extends beyond the document’s range. In this case, you should return the intersection of the document’s range and `theRange`. If the location of `theRange` is completely outside of the document’s range, return `nil`.

---

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)