解读Swift示例

时间:2016-10-31 14:48:12

标签: swift multidimensional-array closures

在我快速学习的过程中,我得到了一些我无法破译的例子。有人可以帮我理解下面的块,特别是没有所有关闭的简写。

        let arrayElement = [Bool](repeating: false, count: 10)
    var before = [[Bool]](repeating: arrayElement, count:10)
   // i is the columns and j is the rows
    for i in 0 ..< arrayElement.count {
        for j in 0 ..< before.count {
            if arc4random_uniform(3) == 1 {
                var row = before[j]
                row[i] = true
                before[j] = row

            }
        }
    }

    let numberOfTrue = (0 ..< before.count).reduce(0) { (accum, row) in
        return accum + before[row].filter { $0 }.count

    }

0 个答案:

没有答案