看看这些短代码产生的差异
var animals: [Character] = ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""]
func setBoard() {
var charToChoose = maxButtons / 2
var charChosen:Character = ""
var j = 0
for var i = 0; i < charToChoose; i++ {
let randomIndex = Int(arc4random_uniform(UInt32(animals.count)))
println("randomIndex = \(randomIndex)")
charChosen = animals[randomIndex]
println("charChosen = \(charChosen)")
boardArray[j] = charChosen
//j++
}
println("printing of board array = \(boardArray)")
}
使用Xcode 6.1.1(6A2008a)的输出
randomIndex = 39 charChosen =
randomIndex = 36 charChosen =
randomIndex = 50 charChosen =
randomIndex = 4 charChosen =
randomIndex = 2 charChosen =
randomIndex = 1 charChosen =
randomIndex = 38 charChosen =
randomIndex = 3 charChosen =
printing of board array = [, , , , , , , ]
仅在watchkit extenxion中使用Xcode 6.2(6C121)的输出
randomIndex = 18 charChosen =
randomIndex = 7 charCsen =
randomIndex = 50 charChon = \360\237\220
randomIndex = 40 charChosen = \360\237\220
randomIndex = 12 charChosen =
randomIndex 3 charChosen =
randomIndex = 5 charChosen = \360
randomIndex = 50
charChosen = \360\237\220
printing of board array = [, , , , , \360\237