Sometimes you want to reduce (sum) the values of an array to a single final value in your swift code, this can easily be achieved by using the Array reduce method.
Sum Array Of Integers
let twenty20 = Array(repeating: 20, count: 20)
let sum = twenty20.reduce(0, +)
print(sum)
Output: 400
let myNumbers = [20, 50, 10, -1, 0, 500]
let sum = myNumbers.reduce(0, +)
basic