ZDCProgress

@interface ZDCProgress : NSProgress

A subclass of NSProgress which simplifies the management of children.

There are 2 major advantages that ZDCProgress has over NSProgress.

  1. It allows children to be removed. Many networking operations within the framework gracefully recover from temporary networking failures. In order to properly maintain the progress, this involves removing progress children from the tree.

  2. It optionally allows children to control their pendingUnitCount within the parent. This is useful when it’s preferred that the parent’s totalUnitCount matches the sum of the children’s totalUnitCount. (i.e. for proper reporting of bytes downloaded)

See

NSProgress
  • Designated initializer

    Declaration

    Objective-C

    - (nonnull instancetype)init;

    Swift

    init()
  • Represents the portion of the progress that comes from already completed child tasks. This is probaly not the value you’re looking for.

    See

    [NSProgress totalUnitCount]

    See

    [NSProgress fractionCompleted]

    Declaration

    Objective-C

    @property (assign, readwrite, atomic) int64_t baseTotalUnitCount;

    Swift

    var baseTotalUnitCount: Int64 { get set }
  • Represents the portion of the progress that comes from already completed child tasks. This is probaly not the value you’re looking for.

    See

    -[NSProgress completedUnitCount]

    See

    -[NSProgress fractionCompleted]

    Declaration

    Objective-C

    @property (assign, readwrite, atomic) int64_t baseCompletedUnitCount;

    Swift

    var baseCompletedUnitCount: Int64 { get set }
  • Declaration

    Objective-C

    - (void)addChild:(nonnull NSProgress *)child
        withPendingUnitCount:(int64_t)pendingUnitCount;

    Swift

    func addChild(_ child: Progress, withPendingUnitCount pendingUnitCount: Int64)

    Parameters

    child

    The child progress item to add

    pendingUnitCount

    If you pass a positive value, the child will be assigned the given value. If you pass zero or a negative value, the child’s pendingUnitCount will automatically update according to child.totalUnitCount.

  • Removes the child from the list of children.

    Declaration

    Objective-C

    - (void)removeChild:(nonnull NSProgress *)child
        andIncrementBaseUnitCount:(BOOL)success;

    Swift

    func removeChild(_ child: Progress, andIncrementBaseUnitCount success: Bool)

    Parameters

    child

    The child progress item to remove

    success

    If YES, the baseCompletedUnitCount is incremented according to the child’s pendingUnitCount. If NO, the baseCompletedUnitCount is unchanged. If the child was added with a non-positive pendingUnitCount, then the baseTotalUnitCount will also be incremented if this parameter is YES. You typically pass YES if the operation was successful, and NO if the operation failed and will be retried (and thus replaced with a new progress).

  • Removes all children from the list of children.

    Declaration

    Objective-C

    - (void)removeAllChildrenAndIncrementBaseUnitCount:(BOOL)success;

    Swift

    func removeAllChildrenAndIncrementBaseUnitCount(_ success: Bool)

    Parameters

    success

    If YES, the baseCompletedUnitCount is incremented according to the child’s pendingUnitCount. If NO, the baseCompletedUnitCount is unchanged. If the child was added with a non-positive pendingUnitCount, then the baseTotalUnitCount will also be incremented if this parameter is YES. You typically pass YES if the operation was successful, and NO if the operation failed and will be retried (and thus replaced with a new progress).

  • Finds & returns the first child progress with the given type.

    This is useful when your UI supports more advanced progress logic. For example, imagine a task that is composed of 2 long running operations: A & B. Both A & B are children of a parent progress, but you’d like to update your UI to display the progress for each type of operation independently.

    Declaration

    Objective-C

    - (nullable NSProgress *)childProgressWithType:(ZDCChildProgressType)type;

    Swift

    func childProgress(with type: ZDCChildProgressType) -> Progress?