我是一个新开发人员,似乎无法弄清楚如何在布尔数组中找到True语句的数量.我知道如何通过索引而不是通过值来查找.任何援助将不胜感激.
let arrayElement = [Bool](repeating: false, count: 10)
var before: [[Bool]] = [[Bool]](repeating: arrayElement, count:10)
for i in 0 ..< 10 {
for j in 0 ..< 10 {
if arc4random_uniform(3) == 1 {
before[i][j] = true
}
}
}
Run Code Online (Sandbox Code Playgroud)