Swift

Strings #

Interpolation #

let name = "Robb"
let myString = "My name is \(name)"

Replacement #

str.replacingOccurrences(of: "this", with: "that")

Split #

myString.components(separatedBy: " ")

Includes #

let myString = "something cool"
// starts with
myString.starts(with: "something")

// contains
myString.contains("something")

// get first or last
myString.prefix(2) // "so"
myString.suffix(2) // "ol"

Arrays #

Join #

myArray.joined(separator: ", ")

Filter #

let filtered = myArray.filter { $0.count > 1 }

Iterate #

for element in elements {
print(element)
}

// or

elements.forEach { element in
print(element)
}

Index Exists #

myArray.indices.contains(1)

Length of Array #

myArray.count