0 votes
asked in Swift by (4k points)
Hi All

  How to set default value all array content while init in Swift?

1 Answer

0 votes
answered by (4.2k points)

Hi Kalpana

   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):

  • var threeDoubles = [Double](count: 3, repeatedValue: 0.0)
  • // threeDoubles is of type [Double], and equals [0.0, 0.0, 0.0]