Search code examples
multithreadingswiftconcurrencygrand-central-dispatch

Pure Swift concurrency


All the libraries I have come across that provide Swift concurrency functionality either depend on an Objective-C library or are wrappers around the C based GCD. (iOS and OS X)

I'm just wondering if anyone knows of a pure Swift concurrency library? No dependencies. Or if not how might we go about making one?


Solution

  • The Swift language doesn't have constructs to support concurrency yet. Rumor has it that those are going to be added to a future version of the language, but in the meantime, I don't think you can do this without OS support.

    GCD makes for fairly clean concurrent solutions in Swift, since GCD blocks are Swift closures. It's not platform-indpendent, however. (At least not outside the Apple ecosystem.)

    Edit:

    I guess you could write a concurrency library that would run on all POSIX-compliant OS's by using POSIX, but Windows isn't really POSIX-compliant, so that might not be a perfect solution either.

    Edit #2:

    In Swift 3 the GCD interface has been cleaned up and made much more "Swifty". Now there is a Dispatch class, that has class methods to do the things that used to use global functions.