尝试将此元组添加到数组时出现上述错误。
struct Cards{
var cards: [(face: String, value: Int, image: UIImage?)] = []
}
var playerCards: [(face: String, value: Int, image: UIImage?)] = []
func dealCards() {
self.createCards()
var turn = 0
for var i = 0; i <= self.cards.cards.count - 1; ++i {
if turn == 0 {
turn = 1
self.playerCards.append((face: self.cards.cards[i].face, value: self.cards.cards[i].value, image: self.cards.cards[i].image))
}
else {
turn = 0
}
}
}
func createCards(){
cards.cards.append(face: "Ace Of Spades", value: 14, image: UIImage(named: "ace_of_spades.png"))
}
答案 0 :(得分:0)
为什么要按UIImage
对象初始化UIImage
个对象?也许这是对的?
func dealCards() {
self.createCards()
var turn = 0
for var i = 0; i <= self.cards.cards.count - 1; ++i {
if turn == 0 {
turn = 1
self.playerCards.append((face: self.cards.cards[i].face, value: self.cards.cards[i].value, image: self.cards.cards[i].image))
} else {
turn = 0
}
}
}
(我还修复了从0
到i
的图像索引)
更新。修补了添加的代码:
func createCards() {
cards.cards.append((face: "Ace Of Spades", value: 14, image: UIImage(named: "ace_of_spades.png")))
}