What language level support (if any) does Swift have for asynchronous programming?

前端 未结 2 469
臣服心动
臣服心动 2021-02-05 09:21

Asynchronous programming is a must for responsive user interfaces when application have to communicate over unpredictable networks (e.g. smart phone applications). The user i

2条回答
  •  一整个雨季
    2021-02-05 09:51

    Swift's approach to asynchronous programming is the same as Objective C's: use Grand Central Dispatch. You can pass closures to gcd dispatch_ functions, just as in ObjC. However, for aesthetic reasons, you can also pass your closure (block) after the close parentheses:

    dispatch_async(dispatch_get_main_queue()) {
        println("async hello world")
    }
    

提交回复
热议问题