Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can swift exit out of the root closure?

Tags:

closures

swift

In Swift, if I'm inside of a closure, that is itself inside of another function, is there a way to exit out of the function itself?

Here's an example of what this might look like using closures from the GCDKit library.

func test() {
    GCDQueue.Default.async {
        print("Print me!")
        return //Is there a statement that does this?
    }.notify(.Main) {
        print("Never print me.")
    }
}
like image 725
Evan Conrad Avatar asked Feb 07 '23 21:02

Evan Conrad


1 Answers

No there is not. Closures run in self-contained environments. For all you know, by the time that closure is executed, the thread on which test() was called is no longer executing the test() method.

like image 129
Adam H. Avatar answered Feb 24 '23 06:02

Adam H.