如何初始化斯威夫特一个数组? [英] 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?
推荐答案
其实,这是斯威夫特用很简单。如在<一个提到href=\"https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID112\">Apple's DOC ,你可以像这样一样重复值初始化数组:
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)
这将使:
[0.0, 0.0, 0.0]
这篇关于如何初始化斯威夫特一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文