我试图以随机顺序生成一个包含字符串的数组,但在函数 randomPile 的末尾总是出现错误“Thread1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)”。下面是我的代码:
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
}
}