Edit: I am not looking for a way to split an array by giving its subarray size, I am looking for a way to split an array by giving the number of subarrays I want. I am saying this because the question has been marked as a duplicate, and the linked question is not what I'm looking for.
My goal would be to take an array like this [String] and turn it into an array like this [[String]], with the subarrays being the parts. Maybe creating a function named partition(into:Int). Sort of like this.
let array = ["1", "2", "3", "4", "5", "6", "7", "8"]
array.shuffle()
array.partition(into:4)
Which would end up like this.
[["3", "1"], ["2", "6"], ["8", "5"], ["4", "7"]]
If there are any extra elements it can add them to any subarray.
Ideally, I would like to remove the extra brackets and the quotation marks to display the list in a TableView, or display each subarray as a TableView section with the rows being the contents of the given subarrays.
3, 1
2, 6
8, 5
4, 7