// An array can be initialized from a string.// ... This approach is slower.
let words5 = "the cat is cute".components(separatedBy: " ")
print(words5)["the", "cat", "is", "cute"]
Array initialize error. Sometimes things do not go our way in life. Here we forget to specify an initialization. We specify the array type, but this is not enough.
var codes: [Int]
// We need to assign "codes" to an empty array before using append.
Variable 'codes' passed by reference before being initialized
An initialization fix. Here we fix the array initialization error from the previous example. We just use an empty array, and the code works.
var codes: [Int] = 
// This code sample works.
In Swift, array initialization can be done in many ways. Typically, I prefer the shortest syntax form possible. But this does not work when array initializations are complex.