In Java, I can do this: int[] a = new int[500];
. However in Swift, there seemed like there's no way I can create such a fixed size array without initializing all the variables in the array(which is quite impossible for an array of 500 elements). My goal here is to create a array of 160 SKSpriteNode.
Asked
Active
Viewed 153 times
0

zbz.lvlv
- 3,597
- 6
- 34
- 38
-
1http://stackoverflow.com/questions/24395105/how-to-create-a-fixed-size-array-of-objects – caleb.breckon Dec 04 '14 at 06:48
-
In Java, those 500 elements are `0`. It's an array of primitives. – Elliott Frisch Dec 04 '14 at 06:51
-
Swift’s Array type also provides an initializer for creating an array of a certain size with all of its values set to a provided default value. You pass this initializer the number of items to be added to the new array (called count) and a default value of the appropriate type (called repeatedValue) – Dharma Dec 04 '14 at 07:00
-
For primitive array, try this... var myArray : [Int] = [Int](count: 10, repeatedValue: 0) – Suresh Kumar Durairaj Dec 04 '14 at 07:00