<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextRange/init(location:end:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextRange(im)initWithLocation:endLocation:"
  },
  "title" : "init(location:end:)"
}
-->

# init(location:end:)

Creates a new text range with the starting and ending locations you specify.

```
init?(location: any NSTextLocation, end endLocation: (any NSTextLocation)?)
```

## Parameters

`location`

The starting location.

`endLocation`

The ending location, or `nil` for an empty range.

## Discussion

Returns an empty range when `endLocation` is `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)