gpt4 book ai didi

ios - 如何在循环中快速将值插入多维数组

转载 作者:行者123 更新时间:2023-11-28 12:46:57 25 4
gpt4 key购买 nike

<分区>

找不到这个问题的答案。

我正在尝试使用类似这样的方法将值插入到多维数组中

_ = transportRef.observeEventType(.ChildAdded, withBlock: { (snapshotOne) in

self.yearList.insert(snapshotOne.key, atIndex: 0)

//print("snapshotone.key " + snapshotOne.key) // prints year

if let snapshotTwo = snapshotOne.children.allObjects as? [FIRDataSnapshot] {

for itemTwo in snapshotTwo {

self.monthList[self.counter].insert(itemTwo.key, atIndex: 0)
}
}

counter += 1
}

我的 counter 在这个循环之外的另一个循环中。事情是我收到一个错误 Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0) 并且在 Playground 上玩耍之后,我意识到这是因为我的 monthList: [[String]] = [[]] 因此没有任何要插入的数组或类似的东西。如果我给它一些初始化,比如 monthList = [["1"], ["2"]] 那么我就可以插入直到 monthList[1]在它给出 monthList[2]

错误之前

帮助?谢谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com