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.6.0
Swift library for working with ranges types: NSRange, NSTextRange, Range, UITextRange, and String.Index
⭐️ 66
🕓 18 weeks ago
.package(url: "https://github.com/ChimeHQ/Rearrange.git", from: "1.6.0")

Build Status Platforms Documentation

Rearrange

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.

Integration

Swift Package Manager:

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

Types

RangeMutation

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.

Extensions

NSRange

// convenience
static let zero: NSRange
static let notFound: NSRange
var max: Int

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

// mutating
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>?

NSTextRange

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

UITextRange

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

IndexSet

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?

String

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

Contributing and Collaboration

I'd love to hear from you! Get in touch via an issue or pull request.

I prefer collaboration, and would love to find ways to work together if you have a similar project.

I prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.

By participating in this project you agree to abide by the Contributor Code of Conduct.

GitHub

link
Stars: 66
Last commit: 1 week ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v1.6.0
18 weeks ago
  • RangeMutation now conforms to Sendable

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