What is different between Async/Await, Combine, Closures?

Hello Kodeco team,

Like the question in the title, I really wonder why apple built so many solutions for concurrency? difference between them? When should it apply?

nghiaphamsg

That’s a fair question. There is a more detailed explanation in Modern Concurrency in Swift | Kodeco, the new raywenderlich.com but I’ll try to summarize it here:

  • Dispatch queues and closures were introduced back in 2009 (if I remember well), they have been working well for 10+ years. Apple would like to move to more modern solutions currently.
  • Combine was released alongside SwiftUI to provide API for building SwiftUI apps and binding data. It’s a modern framework oriented towards building applications on mac and iOS.
  • async/await is a language feature, that’s available anywhere where Swift is available.

Generally speaking, using the newest APIs is best. Combine is relevant and makes some things around building UI and complex apps easier. Async/await is what Apple recommends and is available on all platforms.

3 Likes

thanks for your answer, I think it’s more appropriate to use combine from now on