Iterate over two arrays simultaneously

You can use zip(), which creates a sequence of pairs from the two given sequences: let strArr1 = [“Some1”, “Some2”] let strArr2 = [“Somethingelse1”, “Somethingelse2”] for (e1, e2) in zip(strArr1, strArr2) { print(“\(e1) – \(e2)”) } The sequence enumerates only the “common elements” of the given sequences/arrays. If they have different length then the additional … Read more

New Array from Index Range Swift

This works for me: var test = [1, 2, 3] var n = 2 var test2 = test[0..<n] Your issue could be with how you’re declaring your array to begin with. EDIT: To fix your function, you have to cast your Slice to an array: func aFunction(numbers: Array<Int>, position: Int) -> Array<Int> { var newNumbers … Read more