This is a Swift package that provides a fluent, convenient extensions for working with and manipulating String in a more elegant and expressive manner.
- Open your existing Xcode project or create a new one.
- In the Xcode menu, go to
File > Add Packages....
- In the Search or Enter Package URL field, enter:
https://github.com/rkukuh/Swift-StringHelper.git
.
Press Return to load the package. - After the package is loaded, you will see the package details, including its name, the repository URL, and available versions.
By default, Xcode selects the most recent version. You can choose a specific version, a branch, or a commit using the provided options. - Click
Add Package
to confirm the addition of the package to your project. - Xcode will download the package and add it to your project's Swift Package Dependencies.
You can check this by going to your project settings and selecting thePackage Dependencies
tab. - To use the package in your project, simply import the package module at the top of any Swift file where you want to use it:
import SwiftStringHelper
//...
These following methods are available for working with and manipulating String
native library.
The after()
helper returns the remainder of a string after the first occurrence of a given value.
let originalString = "[email protected]"
let result = originalString.after("@")
print(result) // apple.com
The before()
helper returns the portion of a string before the first occurrence of a given value.
let originalString = "[email protected]"
let result = originalString.before("@")
print(result) // john
The between()
helper returns the portion of a string between two values.
let originalString = "[email protected]"
let result = originalString.between("john@", and: ".com")
print(result) // Optional("apple")
The camelCased()
helper converts the given string to camelCaseLikeThis.
var originalString = "Everyone CAN Code"
var result = originalString.camelCased()
print(result) // everyoneCanCode
The containsAll()
helper determines if the given string contains all of the values in a given array.
let originalString = "[email protected]"
let result = originalString.containsAll(["hello", "@", ".com"])
print(result) // true
let originalString = "[email protected]"
let result = originalString.containsAll(["hello", "@", ".org"])
print(result) // false