public class NSProgress extends NSObject
Since work is often split up into several parts, progress objects can form a tree where children represent part of the overall total work. Each parent may have as many children as required, but each child only has one parent. The top level progress object in this tree is typically the one that you would display to a user. The leaf objects are updated as work completes, and the updates propagate up the tree.
The work that an NSProgress does is tracked via a "unit count." There are two unit count values: total and completed. In its leaf form, an NSProgress is created with a total unit count and its completed unit count is updated with -setCompletedUnitCount: until it matches the total unit count. The progress is then considered finished.
When progress objects form nodes in trees, they are still created with a total unit count. Portions of the total are then handed out to children as a "pending unit count." The total amount handed out to children should add up to the parent's totalUnitCount. When those children become finished, the pending unit count assigned to that child is added to the parent's completedUnitCount. Therefore, when all children are finished, the parent's completedUnitCount is equal to its totalUnitCount and it becomes finished itself.
Children NSProgress objects can be added implicitly or by invoking the -addChild:withPendingUnitCount: method on the parent. Implicitly added children are attached to a parent progress between a call to -becomeCurrentWithPendingUnitCount: and a call to -resignCurrent. The implicit child is created with the +progressWithTotalUnitCount: method or by passing the result of +currentProgress to the -initWithParent:userInfo: method. Both kinds of children can be attached to the same parent progress object. If you have an idea in advance that some portions of the work will take more or less time than the others, you can use different values of pending unit count for each child.
If you are designing an interface of an object that reports progress, then the recommended approach is to vend an NSProgress property and adopt the NSProgressReporting protocol. The progress should be created with the -discreteProgressWithTotalUnitCount: method. You can then either update the progress object directly or set it to have children of its own. Users of your object can compose your progress into their tree by using the -addChild:withPendingUnitCount: method.
If you want to provide progress reporting for a single method, then the recommended approach is to implicitly attach to a current NSProgress by creating an NSProgress object at the very beginning of your method using +progressWithTotalUnitCount:. This progress object will consume the pending unit count, and then you can set up the progress object with children of its own.
The localizedDescription and localizedAdditionalDescription properties are meant to be observed as well as set. So are the cancellable and pausable properties. totalUnitCount and completedUnitCount on the other hand are often not the best properties to observe when presenting progress to the user. For example, you should observe fractionCompleted instead of observing totalUnitCount and completedUnitCount and doing your own calculation. NSProgress' default implementation of fractionCompleted does fairly sophisticated things like taking child NSProgresses into account.
| Modifier and Type | Class and Description |
|---|---|
static interface |
NSProgress.Block_cancellationHandler_ret |
static interface |
NSProgress.Block_pausingHandler_ret |
static interface |
NSProgress.Block_performAsCurrentWithPendingUnitCountUsingBlock |
static interface |
NSProgress.Block_resumingHandler_ret |
static interface |
NSProgress.Block_setCancellationHandler |
static interface |
NSProgress.Block_setPausingHandler |
static interface |
NSProgress.Block_setResumingHandler |
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
NSProgress(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessInstanceVariablesDirectly() |
void |
addChildWithPendingUnitCount(NSProgress child,
long inUnitCount)
Directly add a child progress to the receiver, assigning it a portion of the receiver's total unit count.
|
static NSProgress |
alloc() |
static NSProgress |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
void |
becomeCurrentWithPendingUnitCount(long unitCount)
Make the receiver the current thread's current progress object, returned by +currentProgress.
|
void |
cancel()
Invoke the block registered with the cancellationHandler property, if there is one, and set the cancelled property to YES.
|
NSProgress.Block_cancellationHandler_ret |
cancellationHandler()
A block to be invoked when cancel is invoked.
|
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument) |
static NSArray<java.lang.String> |
classFallbacksForKeyedArchiver() |
static org.moe.natj.objc.Class |
classForKeyedUnarchiver() |
long |
completedUnitCount() |
static NSProgress |
currentProgress()
The instance of NSProgress associated with the current thread by a previous invocation of -becomeCurrentWithPendingUnitCount:, if any.
|
static java.lang.String |
debugDescription_static() |
static java.lang.String |
description_static() |
static NSProgress |
discreteProgressWithTotalUnitCount(long unitCount)
Return an instance of NSProgress that has been initialized with -initWithParent:userInfo:.
|
NSNumber |
estimatedTimeRemaining()
How much time is probably left in the operation, as an NSNumber containing a number of seconds.
|
NSNumber |
fileCompletedCount()
If the progress is operating on a set of files, then set to the number of completed files in the operation.
|
java.lang.String |
fileOperationKind()
When the kind property is NSProgressKindFile, this value should be set.
|
NSNumber |
fileTotalCount()
If the progress is operating on a set of files, then set to the total number of files in the operation.
|
NSURL |
fileURL()
A URL identifying the item on which progress is being made.
|
double |
fractionCompleted()
The fraction of the overall work completed by this progress object, including work done by any children it may have.
|
static long |
hash_static() |
NSProgress |
init() |
NSProgress |
initWithParentUserInfo(NSProgress parentProgressOrNil,
NSDictionary<java.lang.String,?> userInfoOrNil)
The designated initializer.
|
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
boolean |
isCancellable()
Whether the work being done can be cancelled or paused, respectively.
|
boolean |
isCancelled()
Whether the work being done has been cancelled or paused, respectively.
|
boolean |
isFinished()
True if the progress is considered finished.
|
boolean |
isIndeterminate()
Whether the progress being made is indeterminate.
|
boolean |
isPausable() |
boolean |
isPaused() |
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
java.lang.String |
kind()
Either a string identifying what kind of progress is being made, like NSProgressKindFile, or nil.
|
java.lang.String |
localizedAdditionalDescription()
A more specific description of what progress is being made, fit to present to the user.
|
java.lang.String |
localizedDescription()
A description of what progress is being made, fit to present to the user.
|
static NSProgress |
new_objc() |
void |
pause()
Invoke the block registered with the pausingHandler property, if there is one, and set the paused property to YES.
|
NSProgress.Block_pausingHandler_ret |
pausingHandler()
A block to be invoked when pause is invoked.
|
void |
performAsCurrentWithPendingUnitCountUsingBlock(long unitCount,
NSProgress.Block_performAsCurrentWithPendingUnitCountUsingBlock work)
Become current, do some work, then resign current.
|
static NSProgress |
progressWithTotalUnitCount(long unitCount)
Return an instance of NSProgress that has been initialized with -initWithParent:userInfo:.
|
static NSProgress |
progressWithTotalUnitCountParentPendingUnitCount(long unitCount,
NSProgress parent,
long portionOfParentTotalUnitCount)
Return an instance of NSProgress that has been attached to a parent progress with the given pending unit count.
|
void |
resignCurrent()
Balance the most recent previous invocation of -becomeCurrentWithPendingUnitCount: on the same thread by restoring the current progress object to what it was before -becomeCurrentWithPendingUnitCount: was invoked.
|
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
void |
resume()
Invoke the block registered with the resumingHandler property, if there is one, and set the paused property to NO.
|
NSProgress.Block_resumingHandler_ret |
resumingHandler()
A block to be invoked when resume is invoked.
|
void |
setCancellable(boolean value)
Whether the work being done can be cancelled or paused, respectively.
|
void |
setCancellationHandler(NSProgress.Block_setCancellationHandler value)
A block to be invoked when cancel is invoked.
|
void |
setCompletedUnitCount(long value) |
void |
setEstimatedTimeRemaining(NSNumber value)
How much time is probably left in the operation, as an NSNumber containing a number of seconds.
|
void |
setFileCompletedCount(NSNumber value)
If the progress is operating on a set of files, then set to the number of completed files in the operation.
|
void |
setFileOperationKind(java.lang.String value)
When the kind property is NSProgressKindFile, this value should be set.
|
void |
setFileTotalCount(NSNumber value)
If the progress is operating on a set of files, then set to the total number of files in the operation.
|
void |
setFileURL(NSURL value)
A URL identifying the item on which progress is being made.
|
void |
setKind(java.lang.String value)
Either a string identifying what kind of progress is being made, like NSProgressKindFile, or nil.
|
void |
setLocalizedAdditionalDescription(java.lang.String value)
A more specific description of what progress is being made, fit to present to the user.
|
void |
setLocalizedDescription(java.lang.String value)
A description of what progress is being made, fit to present to the user.
|
void |
setPausable(boolean value) |
void |
setPausingHandler(NSProgress.Block_setPausingHandler value)
A block to be invoked when pause is invoked.
|
void |
setResumingHandler(NSProgress.Block_setResumingHandler value)
A block to be invoked when resume is invoked.
|
void |
setThroughput(NSNumber value)
How fast data is being processed, as an NSNumber containing bytes per second.
|
void |
setTotalUnitCount(long value)
The size of the job whose progress is being reported, and how much of it has been completed so far, respectively.
|
void |
setUserInfoObjectForKey(java.lang.Object objectOrNil,
java.lang.String key)
Set a value in the dictionary returned by invocations of -userInfo, with appropriate KVO notification for properties whose values can depend on values in the user info dictionary, like localizedDescription.
|
static void |
setVersion_static(long aVersion) |
static org.moe.natj.objc.Class |
superclass_static() |
NSNumber |
throughput()
How fast data is being processed, as an NSNumber containing bytes per second.
|
long |
totalUnitCount()
The size of the job whose progress is being reported, and how much of it has been completed so far, respectively.
|
NSDictionary<java.lang.String,?> |
userInfo()
Arbitrary values associated with the receiver.
|
static long |
version_static() |
accessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKeypublic static boolean accessInstanceVariablesDirectly()
public static NSProgress alloc()
public static NSProgress allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
public static NSProgress currentProgress()
public static java.lang.String debugDescription_static()
public static java.lang.String description_static()
public static NSProgress discreteProgressWithTotalUnitCount(long unitCount)
public static long hash_static()
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public static NSProgress new_objc()
public static NSProgress progressWithTotalUnitCount(long unitCount)
You can invoke this method on one thread and then message the returned NSProgress on another thread. For example, you can let the result of invoking this method get captured by a block passed to dispatch_async(). In that block you can invoke methods like -becomeCurrentWithPendingUnitCount: and -resignCurrent, or -setCompletedUnitCount: and -isCancelled.
public static NSProgress progressWithTotalUnitCountParentPendingUnitCount(long unitCount, NSProgress parent, long portionOfParentTotalUnitCount)
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
public static void setVersion_static(long aVersion)
public static org.moe.natj.objc.Class superclass_static()
public static long version_static()
public void addChildWithPendingUnitCount(NSProgress child, long inUnitCount)
public void becomeCurrentWithPendingUnitCount(long unitCount)
With this mechanism, code that doesn't know anything about its callers can report progress accurately by using +progressWithTotalUnitCount: and -setCompletedUnitCount:. The calling code will account for the fact that the work done is only a portion of the work to be done as part of a larger operation. The unit of work in a call to -becomeCurrentWithPendingUnitCount: has to be the same unit of work as that used for the value of the totalUnitCount property, but the unit of work used by the child can be a completely different one, and often will be. You must always balance invocations of this method with invocations of -resignCurrent.
public void cancel()
public NSProgress.Block_cancellationHandler_ret cancellationHandler()
public long completedUnitCount()
public double fractionCompleted()
public NSProgress init()
public NSProgress initWithParentUserInfo(NSProgress parentProgressOrNil, NSDictionary<java.lang.String,?> userInfoOrNil)
public boolean isCancellable()
public void setCancellable(boolean value)
public boolean isCancelled()
public boolean isIndeterminate()
public boolean isPausable()
public void setPausable(boolean value)
public boolean isPaused()
public java.lang.String kind()
public java.lang.String localizedAdditionalDescription()
For example, depending on the kind of progress, the completed and total unit counts, and other parameters, these kinds of strings may be generated: 3 of 10 files 123 KB of 789.1 MB 3.3 MB of 103.92 GB — 2 minutes remaining 1.61 GB of 3.22 GB (2 KB/sec) — 2 minutes remaining 1 minute remaining (1 KB/sec)
public java.lang.String localizedDescription()
For example, depending on the kind of progress, the completed and total unit counts, and other parameters, these kinds of strings may be generated: Copying 10 files… 30% completed Copying “TextEdit”…
public void pause()
public NSProgress.Block_pausingHandler_ret pausingHandler()
public void resignCurrent()
public void resume()
public NSProgress.Block_resumingHandler_ret resumingHandler()
public void setCancellationHandler(NSProgress.Block_setCancellationHandler value)
public void setCompletedUnitCount(long value)
public void setKind(java.lang.String value)
public void setLocalizedAdditionalDescription(java.lang.String value)
For example, depending on the kind of progress, the completed and total unit counts, and other parameters, these kinds of strings may be generated: 3 of 10 files 123 KB of 789.1 MB 3.3 MB of 103.92 GB — 2 minutes remaining 1.61 GB of 3.22 GB (2 KB/sec) — 2 minutes remaining 1 minute remaining (1 KB/sec)
public void setLocalizedDescription(java.lang.String value)
For example, depending on the kind of progress, the completed and total unit counts, and other parameters, these kinds of strings may be generated: Copying 10 files… 30% completed Copying “TextEdit”…
public void setPausingHandler(NSProgress.Block_setPausingHandler value)
public void setResumingHandler(NSProgress.Block_setResumingHandler value)
public void setTotalUnitCount(long value)
If the receiver NSProgress object is a "leaf progress" (no children), then the fractionCompleted is generally completedUnitCount / totalUnitCount. If the receiver NSProgress has children, the fractionCompleted will reflect progress made in child objects in addition to its own completedUnitCount. As children finish, the completedUnitCount of the parent will be updated.
public void setUserInfoObjectForKey(java.lang.Object objectOrNil,
java.lang.String key)
public long totalUnitCount()
If the receiver NSProgress object is a "leaf progress" (no children), then the fractionCompleted is generally completedUnitCount / totalUnitCount. If the receiver NSProgress has children, the fractionCompleted will reflect progress made in child objects in addition to its own completedUnitCount. As children finish, the completedUnitCount of the parent will be updated.
public NSDictionary<java.lang.String,?> userInfo()
public NSNumber estimatedTimeRemaining()
public NSNumber fileCompletedCount()
public java.lang.String fileOperationKind()
public NSNumber fileTotalCount()
public NSURL fileURL()
public boolean isFinished()
public void performAsCurrentWithPendingUnitCountUsingBlock(long unitCount,
NSProgress.Block_performAsCurrentWithPendingUnitCountUsingBlock work)
public void setEstimatedTimeRemaining(NSNumber value)
public void setFileCompletedCount(NSNumber value)
public void setFileOperationKind(java.lang.String value)
public void setFileTotalCount(NSNumber value)
public void setFileURL(NSURL value)
public void setThroughput(NSNumber value)
public NSNumber throughput()