Often when working with data from an API or third-party we'll need to manipulate or analyze it in a very specific way. In these cases, many of us simply search Google for "how to do the thing to a String in Swift". This usually works out fine, but what a bummer.

Today we'll check out a library from Andrew Mayne called SwiftString, which can help us here.

SwiftString is essentially a collection of a ton of String manipulation and analysis utilities. It has functions like this:

"<rock>blah</hardplace>" . between ( "<rock>" , "</hardplace>" ) // "blah"

"hello" . isNumeric () // false "hello7" . isNumeric () // false "31.0" . isNumeric () // true "-31.0" . isNumeric () // true

"star wars" . split ( " " )[ 0 ] // "star"

"star wars" [ 0 ... 1 ] // "st"

"#203: Simplifying Common String Operations" . slugify () // "203-simplifying-common-string-operations"

"Some [string], *with* %junk in it.)" . stripPunctuation () // "Some string with junk in it"

"yay "strings"" . decodeHTML () // "yay \"strings\""

We might only need one or two of these functions in a single app, but thanks to SwiftString, we'll never have to write them ourselves again.

More info about SwiftString can be found at git.io/swiftstring