Async Workflows

August 18, 2018

All apps have asynchronous workflows. Apple's NSOperation and NSOperationQueue provide a foundation for building arbitrarily complex workflows. This demo code coincides with my STL CocoaHeads talk on techniques for building "async workflows".

Slides and Demo Code

The demo code shows how to:

  • use dependent operations
  • pass data between operations using a thread-safe key/value store (i.e Session)
  • track progress using NSProgress
  • support an easy to understand cancellation policy
  • allow app background execution (with just a few lines of code)

Be sure to review the CocoaHeads presentation slides for additional notes and details.

Workflows

You can use the techniques described in this talk and the demo code to design and implement some really neat workflows.

Workflows include, but are definitely not limited to:

  • signing in users with dynamic on-boarding steps
  • managing external resources (e.g. large files such as images, SQLite files, etc.)
    • downloading (using background URLSession)
    • decompressing
    • validating
    • file system management
  • any type of web service request
    • building and validating requests
    • transforming the result
    • importing the result into a local data store (i.e. Core Data or SQLite)
  • accessing a local SQLite database
    • extracting
    • transforming
    • publishing results
  • discovering and opening connections to external IP-enabled hardware
  • signing out users

Additional Resources

Here's a short list of related WWDC videos