<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSRange-swift.typealias",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@T@NSRange"
  },
  "title" : "NSRange"
}
-->

# NSRange

A structure used to describe a portion of a series, such as characters in a string or objects in an array.

```
typealias NSRange = _NSRange
```

## Discussion

Foundation functions that operate on ranges include the following:

- [`NSEqualRanges(_:_:)`](/documentation/Foundation/NSEqualRanges(_:_:))
- [`NSIntersectionRange(_:_:)`](/documentation/Foundation/NSIntersectionRange(_:_:))
- [`NSLocationInRange(_:_:)`](/documentation/Foundation/NSLocationInRange(_:_:))
- [`NSMakeRange(_:_:)`](/documentation/Foundation/NSMakeRange(_:_:))
- [`NSMaxRange(_:)`](/documentation/Foundation/NSMaxRange(_:))
- [`NSRangeFromString(_:)`](/documentation/Foundation/NSRangeFromString(_:))
- [`NSStringFromRange(_:)`](/documentation/Foundation/NSStringFromRange(_:))
- [`NSUnionRange(_:_:)`](/documentation/Foundation/NSUnionRange(_:_:))

## Topics

### Creating a range

[`init()`](/documentation/Foundation/NSRange-swift.typealias/init())

Creates an empty range.

[`init(location: Int, length: Int)`](/documentation/Foundation/NSRange-swift.typealias/init(location:length:))

Creates a range with the given location and length.

### Accessing range properties

[`var location: Int`](/documentation/Foundation/NSRange-swift.typealias/location)

The index of the first member of the range.

[`var length: Int`](/documentation/Foundation/NSRange-swift.typealias/length)

The number of items in the range.

### Managing ranges

[`func NSEqualRanges(NSRange, NSRange) -> Bool`](/documentation/Foundation/NSEqualRanges(_:_:))

Returns a Boolean value that indicates whether two given ranges are equal.

[`func NSIntersectionRange(NSRange, NSRange) -> NSRange`](/documentation/Foundation/NSIntersectionRange(_:_:))

Returns the intersection of the specified ranges.

[`func NSLocationInRange(Int, NSRange) -> Bool`](/documentation/Foundation/NSLocationInRange(_:_:))

Returns a Boolean value that indicates whether a specified position is in a given range.

[`func NSMakeRange(Int, Int) -> NSRange`](/documentation/Foundation/NSMakeRange(_:_:))

Creates a new NSRange from the specified values.

[`func NSMaxRange(NSRange) -> Int`](/documentation/Foundation/NSMaxRange(_:))

Returns the sum of the location and length of the range.

[`func NSRangeFromString(String) -> NSRange`](/documentation/Foundation/NSRangeFromString(_:))

Returns a range from a textual representation.

[`func NSStringFromRange(NSRange) -> String`](/documentation/Foundation/NSStringFromRange(_:))

Returns a string representation of a range.

[`func NSUnionRange(NSRange, NSRange) -> NSRange`](/documentation/Foundation/NSUnionRange(_:_:))

Returns the union of the specified ranges.

### Related types

[`typealias NSRangePointer`](/documentation/Foundation/NSRangePointer)

Type indicating a parameter is a pointer to an `NSRange` structure.

[`var NSNotFound: Int`](/documentation/Foundation/NSNotFound-4qp9h)

A value indicating that a requested item couldn’t be found or doesn’t exist.

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`Decodable`](/documentation/Swift/Decodable)

[`CustomReflectable`](/documentation/Swift/CustomReflectable)

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`Encodable`](/documentation/Swift/Encodable)

---

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)