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

# location(_:offsetBy:)

Returns a new text location object based on an existing location and offset you provide.

```
func location(_ location: any NSTextLocation, offsetBy offset: Int) -> (any NSTextLocation)?
```

## Parameters

`location`

The starting location. For example, you might specify the beginning or end of the document as the starting location.

`offset`

The number of characters from the starting location. Specify a positive integer to create a location object that comes after the starting location. Specify a negative number to create a location object that comes before the starting location.

## Return Value

An [`NSTextLocation`](/documentation/AppKit/NSTextLocation) object that corresponds to the new location, or `nil` if the new location exceeds the bounds of the text.

## Discussion

You can get [`NSTextLocation`](/documentation/AppKit/NSTextLocation) objects for the start and end of the text storage from the [`documentRange`](/documentation/AppKit/NSTextElementProvider/documentRange) property of the [`NSTextElementProvider`](/documentation/AppKit/NSTextElementProvider) protocol, which [`NSTextContentStorage`](/documentation/AppKit/NSTextContentStorage) implements. If you provide an [`NSTextLocation`](/documentation/AppKit/NSTextLocation) object doesn’t match the type of the ones in the [`documentRange`](/documentation/AppKit/NSTextElementProvider/documentRange) property, this method throws an exception.

---

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)