NSProgress Documentation Conflicts
Wait...what? The new
NSProgress
stuff onNSOperationQueue
says you have to callsuper.start()
to contribute towards progress, but Foundation docs forNSOperation
say to never callsuper.start()
O.o
NSOperation.h:
The
progress
property represents a total progress of the operations executed in the queue. By default NSOperationQueue does not report progress until thetotalUnitCount
of the progress is set. When thetotalUnitCount
property 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 overridestart
and do not invokesuper
will not contribute to progress).
At no time in your
start
method should you ever callsuper
. When you define a concurrent operation, you take it upon yourself to provide the same behavior that the defaultstart
method provides, which includes starting the task and generating the appropriate KVO notifications.
Let’s just replace a
NSProgress
helper 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:
-isIndeterminate
returnsYES
when the value of thetotalUnitCount
orcompletedUnitCount
property 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;-isIndeterminate
returnsNO
and-fractionCompleted
returns 1.0 in that case.
Progress is indeterminate when the value of both
totalUnitCount
andcompletedUnitCount
are 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
NSProgress
API.
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 setcompletedUnitCount
too many times on a background thread, app’s memory grows uncontrollably and eventually hits the memory limit 😨