Swiftpack.co - ChimeHQ/Rearrange as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ChimeHQ.
ChimeHQ/Rearrange 1.5.3
Swift library for working with ranges types: NSRange, NSTextRange, Range, UITextRange, and String.Index
⭐️ 39
🕓 4 days ago
.package(url: "https://github.com/ChimeHQ/Rearrange.git", from: "1.5.3")

Build Status License Platforms


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


Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/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: NSRange
static var notFound: NSRange
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
public func clamped(to limit: Int) -> NSRange

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

// creating
init(_ textRange: NSTextRange, provider: NSTextElementProvider)
init?(_ textRange: UITextRange, textView: UITextView)

// working with Swift String
func range(in string: String) -> Range<String.Index>?


// creating
convenience init?(_ range: NSRange, provider: NSTextElementProvider)
convenience init?(_ offset: Int, provider: NSTextElementProvider)


// creating
convenience init?(_ range: NSRange, provider: NSTextElementProvider)


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


subscript(range: Range<Int>) -> Substring?
subscript(range: NSRange) -> Substring?

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: 39
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

4 days ago
  • change preconditions to assertions

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics