For example, in python I could say something along the lines of
arr = range(0,30)
and get an array with said elements. I suspect that something similar might be possible with a subscript in Swift, but after scouring the documentation and Apple's iBook I can't find a "batteries-included" solution for generating said array.
Is this something I'd have to write the code manually for, or is there a pre-written method for it?
You can use this to create array that contains same value
Or if you want to create an array from range you can do it like this
In this case you will get an array that contains Int values from 1 to 10
create an Int array from 0 to N-1
create a Float array from 0 to N-1
create a float array from 0 to 2π including 2π step 0.1
You can create an array with a range like this:
This give you an array of
[0, ..., 100]
You can create a range and map it into an array:
The
map
closure simply returns the range element, resulting in an array whose elements are all integers included in the range. Of course it's possible to generate different element and types, such as:which generates an array of strings
Index0
,Index1
, etc.