Monday, August 31, 2015

NSProgress Enhancements

Jaanus Kase:

One important conceptual update is that we can now use and compose NSProgress in two ways. Implicit composition is what was there before, with the notion of the current progress object for a thread. That continues to work as before. In addition, though, there is a new method of explicit composition that Apple recommends using if you control all the pieces of a system.

[…]

The new explicit composition brings along a much clearer way of working with task weights (or child NSProgress weights).

WWDC 2015 Session 232 (video, PDF):

So all of the properties on NSProgress are key value observable, clients can add the KVO observers to update their UI.

For example, a client can update their UI progress views progress with the NSProgress as fractionCompleted property, or update a label with a localizedDescription.

Also be aware, that these KVO callbacks might not necessarily be called on the main thread.

[…]

Don’t use fractionCompleted to determine completion. […] Use completedUnitCount and totalUnitCount instead, unless your progress is indeterminate or the totalUnitCount is 0.

2 Comments RSS · Twitter


Honestly, I love this particular API. Such a useful and (IMO) underused tool.


@Eric Yep. Perhaps underused on the Mac, thus far, because it requires 10.9.

Leave a Comment