NSProgress parent doesn't have the fraction completed accuracy I would expect
| Originator: | niels | ||
| Number: | rdar://16444353 | Date Originated: | 27-Mar-2014 |
| Status: | Duplicate of 14970750 (Closed) | Resolved: | |
| Product: | iOS SDK | Product Version: | iOS 7.1 (11D167) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
When NSProgress is used with a tree of progress objects as described in the documentation at https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSProgress_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40013490-CH1-SW46 , the fractionCompleted of the parent progress object is not as accurate as one would expect. Dependent on the totalUnitCount of the child progress object and the totalUnitCount and pendingUnitCount of the parent progress object, the fractionCompleted is slightly less than the expected value or completely unexpected values.
Steps to Reproduce:
Run the attached Xcode project, with the following code:
@implementation NVHViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self parentProgressWithTotalCount:1 pendingUnitCount:1 childUnitCount:49999];
[self parentProgressWithTotalCount:1 pendingUnitCount:1 childUnitCount:50000];
[self parentProgressWithTotalCount:2 pendingUnitCount:1 childUnitCount:38936];
[self parentProgressWithTotalCount:2 pendingUnitCount:1 childUnitCount:38937];
[self parentProgressWithTotalCount:4 pendingUnitCount:1 childUnitCount:23444];
[self parentProgressWithTotalCount:4 pendingUnitCount:1 childUnitCount:23445];
[self parentProgressWithTotalCount:5 pendingUnitCount:1 childUnitCount:16988];
[self parentProgressWithTotalCount:5 pendingUnitCount:1 childUnitCount:16989];
}
- (void)parentProgressWithTotalCount:(int64_t)total pendingUnitCount:(int64_t)pending childUnitCount:(int64_t)childUnitCount {
NSLog(@"Total %lld, Pending %lld, Child %lld",total,pending,childUnitCount);
NSProgress* parentProgress = [NSProgress progressWithTotalUnitCount:total];
[parentProgress becomeCurrentWithPendingUnitCount:pending];
NSProgress* childProgress = [self workWithTotalUnitCount:childUnitCount];
NSAssert(childProgress.fractionCompleted == 1, @"Child progress should be fully completed");
[parentProgress resignCurrent];
NSLog(@"Parent progress %@",parentProgress);
}
- (NSProgress*)workWithTotalUnitCount:(int64_t)total {
NSProgress *childTaskProgress = [NSProgress progressWithTotalUnitCount:total];
for (NSUInteger i = 0; i <= total; i+=1) {
childTaskProgress.completedUnitCount = i;
}
NSLog(@"Child progress %@",childTaskProgress);
return childTaskProgress;
}
@end
Expected Results:
The console output should be similar to
2014-03-27 15:04:31.332 NSProgressBug[21495:60b] Total 1, Pending 1, Child 49999
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Total 1, Pending 1, Child 50000
2014-03-27 15:04:31.462 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.463 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.463 NSProgressBug[21495:60b] Total 2, Pending 1, Child 38936
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.500000>
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Total 2, Pending 1, Child 38937
2014-03-27 15:04:31.561 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.562 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.500000>
2014-03-27 15:04:31.562 NSProgressBug[21495:60b] Total 4, Pending 1, Child 23444
2014-03-27 15:04:31.592 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.592 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.250000>
2014-03-27 15:04:31.593 NSProgressBug[21495:60b] Total 4, Pending 1, Child 23445
2014-03-27 15:04:31.622 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.623 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.250000>
2014-03-27 15:04:31.623 NSProgressBug[21495:60b] Total 5, Pending 1, Child 16988
2014-03-27 15:04:31.646 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.646 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.200000>
2014-03-27 15:04:31.647 NSProgressBug[21495:60b] Total 5, Pending 1, Child 16989
2014-03-27 15:04:31.667 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.668 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.200000>
So the progress of the Parent progress should be always equal to 1 / (the number of total parent units)
Actual Results:
But the output is equal to
2014-03-27 15:04:31.332 NSProgressBug[21495:60b] Total 1, Pending 1, Child 49999
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.400 NSProgressBug[21495:60b] Total 1, Pending 1, Child 50000
2014-03-27 15:04:31.462 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.463 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.999970>
2014-03-27 15:04:31.463 NSProgressBug[21495:60b] Total 2, Pending 1, Child 38936
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.500000>
2014-03-27 15:04:31.510 NSProgressBug[21495:60b] Total 2, Pending 1, Child 38937
2014-03-27 15:04:31.561 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.562 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.499990>
2014-03-27 15:04:31.562 NSProgressBug[21495:60b] Total 4, Pending 1, Child 23444
2014-03-27 15:04:31.592 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.592 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.250000>
2014-03-27 15:04:31.593 NSProgressBug[21495:60b] Total 4, Pending 1, Child 23445
2014-03-27 15:04:31.622 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.623 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.249980>
2014-03-27 15:04:31.623 NSProgressBug[21495:60b] Total 5, Pending 1, Child 16988
2014-03-27 15:04:31.646 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.646 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.200000>
2014-03-27 15:04:31.647 NSProgressBug[21495:60b] Total 5, Pending 1, Child 16989
2014-03-27 15:04:31.667 NSProgressBug[21495:60b] Child progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=1.000000>
2014-03-27 15:04:31.668 NSProgressBug[21495:60b] Parent progress <NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.199990>
Here, the parent progress is slightly less than 1/ (the number of total parent units)
Version:
iOS 7.1 (11D167)
Notes:
Configuration:
Tested on iPhone 5s running iOS7.1 and in the simulator running iOS7.1 (both 32 and 64 bit versions)
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!