Skip to content

Commit 9bc23db

Browse files
committedApr 15, 2020
Added method -[SSYProgressView incrementAndRunDoubleValueBy:].
1 parent 057c507 commit 9bc23db

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎SSYProgressView.h

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ extern float const SSYProgressPriorityRegular;
192192
*/
193193
- (void)incrementDoubleValueBy:(double)value ;
194194

195+
/*!
196+
@brief Sets the receiver to show a progress bar, increments
197+
its doubleValue (the progress value) by a given value, and runs the
198+
main run loop.
199+
200+
@details This is useful if you want the receiver's view to update
201+
before long-running operations continue on the main therad.
202+
*/
203+
- (void)incrementAndRunDoubleValueBy:(double)value ;
204+
195205
/*!
196206
@brief Sets the receiver to show a progress bar, and increments
197207
its doubleValue (the progress value) by a given value wrapped in

‎SSYProgressView.m

+15
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,21 @@ - (void)incrementDoubleValueBy:(double)delta {
10071007
[self setDoubleValue:newProgressValue] ;
10081008
}
10091009

1010+
- (void)incrementAndRunDoubleValueBy:(double)delta {
1011+
double newProgressValue = [self progressValue] + delta ;
1012+
[self setProgressValue:newProgressValue] ;
1013+
NSTimeInterval secondsNow = [NSDate timeIntervalSinceReferenceDate] ;
1014+
if (secondsNow > [self nextProgressUpdate]) {
1015+
[self setNextProgressUpdate:(secondsNow + PROGRESS_UPDATE_PERIOD)] ;
1016+
[NSInvocation invokeOnMainThreadTarget:self
1017+
selector:@selector(unsafeSetDoubleValue:)
1018+
retainArguments:YES
1019+
waitUntilDone:YES
1020+
argumentAddresses:&newProgressValue] ;
1021+
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate date]];
1022+
}
1023+
}
1024+
10101025
- (void)incrementDoubleValueByObject:(NSNumber*)value {
10111026
[self incrementDoubleValueBy:[value doubleValue]] ;
10121027
}

0 commit comments

Comments
 (0)