Swiftpack.co - Package - ChimeHQ/Rearrange

Github CI Carthage compatible


Rearrange is a collection of utilities for making it easier to work with NSRange. It's particularly handy when used with the Cocoa text system.


Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/ChimeHQ/Rearrange.git")


github "ChimeHQ/Rearrange"



This is a struct that encapsulates a single change to an NSRange. It's useful for serializing, queuing, or otherwise storing changes and applying them.

You can also use this class to tranform individual points or other NSRanges. This is handy for updating a set of stored NSRanges as text is changed. This might seem easy, but there are a large number of edge cases that RangeMutation handles, including mutations that invalidate (for example completely delete) a range.



// convenience
static var zero
var max: Int

// shifting
public func shifted(by delta: Int) -> NSRange?
public func shifted(startBy delta: Int) -> NSRange?
public func shifted(endBy delta: Int) -> NSRange?

// mutating
func apply(_ change: RangeMutation) -> NSRange?


mutating func insert(range: NSRange)
mutating func insert(ranges: [NSRange])
var nsRangeView: [NSRange]
func contains(integersIn range: NSRange) -> Bool
var limitSpanningRange: NSRange?

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


Stars: 15


Used By

Total: 0


v1.1.6 - 2020-08-25 20:27:10

New API for for overlap/affect detection

v1.1.5 - 2020-04-16 14:43:01

  • Documentation for limitSpanningRange
  • NSRange now conforms to Sequence

v1.1.4 - 2020-04-10 16:41:52

Fixes to how NSRange.apply checks invariants

v1.1.3 - 2020-04-10 15:43:54

Improve invariant checks for range mutation transformations

v1.1.2 - 2019-12-12 19:48:00

  • few more IndexSet extensions
  • fixed up RangeMutation checks
  • fixed a subtle RangeMutation bug

v1.1.1 - 2019-09-11 17:26:14

  • Fixes for multiplatform testing
  • Expanded documentation

v1.1 - 2019-07-07 12:04:04

IndexSet helpers

v1.0 - 2019-06-20 19:46:38

First release!