这是我的代码:
let slotImages = ["SlotImage1", "SlotImage2", "SlotImage3", "SlotImage4", "SlotImage5", "SlotImage6", "SlotImage7", "SlotImage8", "SlotImage9", "SlotImage10"]
class cardsMinigame{
let cardImage: UIImage
let cardValue: Int
init(cardImage: UIImage, cardValue: Int){
self.cardImage = cardImage
self.cardValue = cardValue
}
}
var fakeCards = [[cardsMinigame](), [cardsMinigame](), [cardsMinigame]()]
在为fakeCards添加值时,使用此代码时,我收到错误"致命错误:索引超出数组" (错误也在这一行):
fakeCards[i].append(cardsMinigame(cardImage: UIImage(named:"\(slotImages[random])")!, cardValue: random))
(其中i是0/1/2,随机是< 10)
怎么会发生这种情况?我将一些东西附加到一个空数组中,我不知道为什么它没有索引......