Andi Andi - 1 year ago 66
Swift Question

Execute an function after ending the function before

I would like to know, what's the best way to realisation that in Swift 2 in xCode:
How can I execute the second function after ending the first function, and then function number 3, then 4. And so on?

Answer Source

Given 2 functions func0 and func1, you must add to the param of func0 a closure having the same signature of func1.

func func0(completion: () -> ()) {
    defer { completion() }

func func1() {

Now simply call them writing

func0 { func1() }


// func0
// func1

Repeat the same technique for more functions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download