String+ is an extension for the Swift String class that provides additional functionalities for string manipulation.
Single Int Subscripting
let str = "Hello, World!"
let char = str[0] // Returns: "H"
Range Int subcripting
let str = "Hello, World!"
let substring = str[0..<5] // Returns: "Hello"
The <| operator is used to return the first argument if it is not nil nor empty; otherwise, it returns the second argument.
let str1: String = ""
let str2 = "Default Value"
let result = str1 <| str2 // Returns: "Default Value"
Example
let str = "Hello, World!"
let char = str[0] // Returns: "H"
let substring = str[0..<5] // Returns: "Hello"
let str1: String? = nil
let str2 = "Default Value"
let result = str1 <| str2 // Returns: "Default Value"