To split an array in Swift, you can use the Array slice method.
In this example,
numbers
with integer elements.suffix
method of numbers
to split it into slices based on indices.suffix
method returns a slice of the array.let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
let slice1 = numbers[0..<3]
let slice2 = numbers[3..<6]
let slice3 = numbers[6..<9]
print(slice1, slice2, slice3)
[1, 2, 3] [4, 5, 6] [7, 8, 9]
In this tutorial, we learned How to Split an Array in Swift language with well detailed examples.