【发布时间】:2019-11-20 10:49:20
【问题描述】:
我想按行组织一个多维数组。 我有一个从一个主数组创建 3 个数组的函数。理想情况下,我想将这些子数组以列的形式添加到新数组中。
我尝试了以下方法:
/* Note
-subArray is a data structure where i have 3 values stored at each
index index. these are named data1, data2, data3. I'm accessing them
with the line chamberOne.append(thing.data1). this is referenced
from tempCount's data.
- data structure:
at index # 1
-data1
-data1
-data3
*/
static func subArray()->[String]
{
var temp = mainArray[0...11]
let tempCount = Array(temp)
var returnArr: [String] = []
var chamberOne: [String] = []
for thing in tempCount
{
chamberOne.append(thing.data1)
}
// i have 2 more functions built the same as chamberOne, but they
//are named chamberTwo and chamberThree
//as of right now I am appending like this
returnArr + chamberOne + chamberTwo + chamberThree
// this brings all the data into a single dimension array.
}
我想要一种将chamberOne、chamberTwo 和chamberThree 追加为列或行的方法,两者都可以,我只想通过追加一维数组将某种形式的组织组织到多维空间中(@987654325 @) 到一个多维数组 (returnArr)。
【问题讨论】:
-
房间是否相同
length或者可以是任何长度? -
长度都一样
标签: arrays swift multidimensional-array append