I want to create a function that takes in a one-dimensional array of numbers and a shape, and returns an array that contains those numbers that has the shape given. For instance if I give it the array [1, 2, 3, 4] and the shape [2, 2] I want it to give me the two dimensional array [[1, 2], [3, 4]].
I know this is pretty simple, but my problem is specifying a return type. I would like to avoid just using the [Any] return type for the function. Like if the given shape is two-dimensional, the return type should be [[Int]], 3 dimensional [[[Int]]], etc. How would I specify an integer array with an arbitrary number of dimensions as the return type? Is this even possible?
I'm pretty new to swift so I don't fully understand the whole philosophy of it yet. Thanks!