m_power m_power - 2 years ago 101
Swift Question

How to initialize an array in Swift?

I have a large array in Swift. I want to initialize all members to the same value (i.e. it could be zero or some other value). What would be the best approach?

Answer Source

Actually, it's quite simple with Swift. As mentioned in the Apple's doc, you can initialize an array with the same repeated value like this:

var threeDoubles = [Double](count: 3, repeatedValue: 0.0)

which would give:

[0.0, 0.0, 0.0]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download