I wrote a really simple bubble sort for a card game. It takes an array of "Card" objects, each of which has a an "order" attribute which indicates the value to be sorted against for the game in question.
The following code stopped compiling some time between Swift Beta 1 and Beta 6, and I'm not exactly sure why.
///Sort the cards array by order
func sortCards(cards: Array<Card>) -> Array<Card> {
var sorted = false
while sorted == false {
sorted = true
for i in 0...cards.count - 2 {
if cards[i].order > cards[i+1].order {
sorted = false
var first = cards[i]
var second = cards[i + 1]
cards[i] = second //ERROR
cards[i + 1] = first //ERROR
}
}
}
return cards
}
The lines where the swap occurs bombs out with a very cryptic message:
@!value $T5 is not identical to 'Card'
What changed, and what am I doing wrong here?
Bonus question: How am I supposed to understand the error message?
[Card]instead ofArray<Card>.