[Solved] Question on how to split a string into an array of desired strings in Swift


You can use reduce to iterate the string over each character and either append it to an array if it is an uppercase letter or add it to the last element of the array otherwise

let str = "F'2R'UU2"

let res = str.reduce(into: [String]()) {
    if $1.isUppercase || $0.isEmpty {
        $0.append("\($1)") 
    } else {
        $0[$0.count - 1] = $0.last! + "\($1)"
    }
}

1

solved Question on how to split a string into an array of desired strings in Swift