I tried to generate an array with strings in random order, but always got the error "Thread1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" at the end of function randomPile. Below is my code:
import UIKit
class RandomView: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var cardOrder = ["HeartSix","HeartNine", "ClubQueen", "SpadeKing" ]
// cannot randomlize due to the lanuage drawbacks.
cardOrder = randomPile(cardOrder)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// random the order of the original card pile
func randomPile(arrayPile: String[]) -> String[] {
var arry = arrayPile
for( var i = arry.count-1; i > 0; --i){
var r = Int(arc4random())%(i+1)
var a = arry[r]
arry[r] = arry[i]
arry[i] = a
}
return arry
}
}