【问题标题】:access series of arrays with a loop使用循环访问一系列数组
【发布时间】:2016-06-21 19:46:57
【问题描述】:

我需要通过它们的名称一一访问一些数组,但是因为它们将被一一调用,所以我无法通过直接调用它们的名称来访问它们。 我所拥有的是这样的:

var cat1 : []
var cat2 : []
var cat3 : []
var cat4 : []
var cat5 : []

for () {
"Here there is some code that is different based on which array I'm dealing with"
}

我不知道如何为此编写“for循环”。

【问题讨论】:

  • 创建一个数组数组:var allCats = [cat1, cat2, cat3, cat4, cat5] 并在allCats 上创建一个外循环。

标签: arrays swift loops


【解决方案1】:

你可以创建一个数组数组:

let cats = [cat1, cat2, cat3, cat4, cat5]

for cat in cats {

}

这很可疑。你到底想做什么?

【讨论】:

    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2015-09-05
    • 2020-05-03
    相关资源
    最近更新 更多