NSProgress iOS 9

In a prior post we reviewed progress reporting using iOS 8. The newest version of iOS made some significantly helpful changes to the existing API for progress reporting. This post will outline the changes/improvements to Progress in iOS 9.

In iOS 8 Progress was thread specific with all the initializers and instance methods operating on the currentProgress object. This approach is now referred to as implicit composition by Apple and continues to work in the manner described previously (previous post). The implicit approach uses the existing API. In iOS 9 Apple has introduced the notion of explicit composition(now the preferred approach). While implicit composition is equivalent to the API under iOS 8, explicit composition is accessed through new API methods:

The additional API makes it appropriate to expose a progress object as a property of a class, because the progress object can now be retrieved and directly added as a child of another progress object. Apple recommends using explicit composition whenever possible. If you need to support versions prior to iOS 9 then you must use implicit composition. You may also have to use the implicit methods to compose trees when the progress object is not directly accessible, for example calling through a proxy object, or through an existing method which cannot gain an Progress.

A new protocol has also been added, ProgressReporting, which can be adopted to mark a class which reports progress in this way. When creating a progress object that will be vended from your class, you most likely want to use the new class method discreteProgress to ensure you are creating a progress object which does not get implicitly attached to the current progress.

iOS 9 also allows for the notion of weighting components of a child process. For example if you have a file download process and a JSON parsing process to report progress on, you can now weight these more appropriately with steps to show the expected relative time of each task more accurately in the UI.

Apple Sample Code PhotoProgress

NSProgress with NSOperations iOS 9

Release Notes

Originally published at dennis-walsh.tumblr.com