Actually, it is quite simple with Swift. As mentioned in the Apple doc , you can initialize an array with the same duplicate value as this:
With the old version of Swift :
var threeDoubles = [Double](count: 3, repeatedValue: 0.0)
Since Swift 3.0 :
var threeDoubles = [Double](repeating: 0.0, count: 3)
which would give:
[0.0, 0.0, 0.0]
moumoute6919 Jun 12 '14 at 2:37 a.m. 2014-06-12 02:37
source share