Andi Andi - 24 days ago 4
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

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() }
    print("func0")
}

func func1() {
    print("func1")
}

Now simply call them writing

func0 { func1() }

Output

// func0
// func1

Repeat the same technique for more functions.