NSProgress Documentation Conflicts
Wait...what? The new
NSProgressstuff onNSOperationQueuesays you have to callsuper.start()to contribute towards progress, but Foundation docs forNSOperationsay to never callsuper.start()O.o
NSOperation.h:
The
progressproperty represents a total progress of the operations executed in the queue. By default NSOperationQueue does not report progress until thetotalUnitCountof the progress is set. When thetotalUnitCountproperty of the progress is set the queue then opts into participating in progress reporting. When enabled, each operation will contribute 1 unit of completion to the overall progress of the queue for operations that are finished by the end of main (operations that overridestartand do not invokesuperwill not contribute to progress).
At no time in your
startmethod should you ever callsuper. When you define a concurrent operation, you take it upon yourself to provide the same behavior that the defaultstartmethod provides, which includes starting the task and generating the appropriate KVO notifications.
Let’s just replace a
NSProgresshelper with built-in API. Easy. A day later we’re still trying to figure out if we even know how this API is supposed to be used. Spoiler: The header is right. As usual. Never rely just on the generated docs.
NSProgress.h:
-isIndeterminatereturnsYESwhen the value of thetotalUnitCountorcompletedUnitCountproperty is less than zero. Zero values for both of those properties indicates that there turned out to not be any work to do after all;-isIndeterminatereturnsNOand-fractionCompletedreturns 1.0 in that case.
Progress is indeterminate when the value of both
totalUnitCountandcompletedUnitCountare zero.
Previously:
- NSProgress
- An Example on How to Use NSProgress
- NSProgress Enhancements
- NSProgress Shortcomings and CSProgress
Update (2020-05-06): Peter Steinberger:
UIKit folks, there’s a radar from 2017 about wrongly documented
NSProgressAPI.
Update (2020-05-19): Noah Gilmore:
Oh man, this just reminded me of a nasty customer-facing issue we fixed with
NSProgress. Turns out that if you setcompletedUnitCounttoo many times on a background thread, app’s memory grows uncontrollably and eventually hits the memory limit 😨