I have an array of Strings. For example, this:
var stringArray1 = ["abcdef", "bcdefg", "cdefgh"]
I want to mutate the array and take out the first 3 characters of each string. The result would be this:
var newStringArray1 = ["def", "efg", "fgh"]
Taking from Apple's Documentation, I tried this:
func mutateArray(x: [String]) -> [String] {
var newArray = [String]()
for i in x {
let range = i.startIndex.advancedBy(3)
i.removeRange(range)
newArray.append(i)
}
return newArray
}
but this line:
i.removeRange(range)
gave me an error: "Cannot use mutating member on mutable value: "i" is a "let" constant."
how can I change the array like this? I have heard it is possible with the map() function as well, but when searching about the map function, most of the explanations I received were from swift 1/1.2, and it changed in swift 2.
thanks