zonble/humanstring
HumanString is a package that let you use integers but not String.Index to
Installation
You can install the package using Swift package manager. Add the following lines to your Packages.swift file:
dependencies: [
.package(url: "https://github.com/zonble/HumanString.git"),
],You can also install the library using CocoaPods, just add pod "HumanString" to you Podfile.
Notes
Swift adopts String.Index since Swift 4. It tends to reminder you that the width of a string is not fixed (SeeStrings in Swift 4). However, it is somehow painful. For example, if you want to extract a prefix from "Hello World", it could be:
let str = "Hello World"
let subString = s[...str.index(str.startIndex, offsetBy: 5)]But wait, somehow you are still using integers, right? The code above could be written as:
let subString = s[str.index(str.startIndex, offsetBy: 0)...str.index(str.startIndex, offsetBy: 5)]I know the Swift team does not like what I am doing here, but somehow I still want to make my life easier.
Package Metadata
Repository: zonble/humanstring
Default branch: master
README: README.md