<分区>
找不到这个问题的答案。
我正在尝试使用类似这样的方法将值插入到多维数组中
_ = 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]
帮助?谢谢