ランダムな順序で文字列を含む配列を生成しようとしましたが、関数 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
}
}