为什么此代码将 6 个元素计为 9 个(“错误”)在 swift 操场上。
var stringArray = ["1", "2", "3", "4", "5", "6"]
for var i = 0; i < 3; i++ {
stringArray.append("Paragraph" + "\(i)")
}
func concat (array: [String]) -> String {
let count = UInt32(stringArray.count) ** --> =9 **
let randomNumberOne = Int(arc4random_uniform(count))
let randomNumberTwo = Int(arc4random_uniform(count))
let randomNumberThree = Int(arc4random_uniform(count))
let concatString = array[randomNumberOne] + array[randomNumberTwo] + array[randomNumberThree]
return concatString
}
let finalString = concat(stringArray)
...但将此代码计为 6(正确)
var stringArray = ["1", "2", "3", "4", "5", "6"] ** --> =6 **
let count = UInt32(stringArray.count)
它与 64 与 32 位有关吗?我有 Xcode 版本 6.0 (6A313)。