Q:

How to get a sum of some closures

2 simple functions with escaping closures
func A(closure: @escaping (Int) -> () {
       //some delay
         closure(value1)
    }

func B(closure: @escaping (Int) -> () {
   //some delay
     closure(value2)
}

In other function I need to get sum of value1 and value2
for example 
func sum(completion: @escaping: (Int)->()){
     A(closure: { value1 in
        B(closure: { value2 in 
           sum = value1 + value2
           completion(sum)
        })
     })
}

But I don't understand what to do if I need to sum results of many functions

A:

You can use DispatchGroup 
    func a(closure: @escaping (Int) -> ()) {
       //some delay
         closure(value1)
    }

    func b(closure: @escaping (Int) -> ()) {
       //some delay
         closure(value2)
    }

    func c(closure: @escaping (Int) -> ()) {
       //some delay
         closure(value3)
    }

    func sum(completion: @escaping: (Int)->()){
        let g = DispatchGroup()
        var sum = 0
         g.enter()
         a(closure: { value1 in
            sum += value1
            g.leave()
         })
         g.enter()
        b(closure: { value2 in
           sum += value2
           g.leave()
        })
         g.enter()
        c(closure: { value3 in
           sum += value3
           g.leave()
        })

        g.notify(queue: .main) {
            completion(sum)
        }

    }

