@@ -26,6 +26,7 @@ class ViewController: UITableViewController {
2626
2727 private var timer : Timer ?
2828 private var status : String ?
29+ private var counter = 0.0
2930
3031 private let textShort = " Please wait... "
3132 private let textLong = " Please wait. We need some more time to work out this situation. "
@@ -113,18 +114,23 @@ extension ViewController {
113114 //-------------------------------------------------------------------------------------------------------------------------------------------
114115 func actionProgressStart( _ status: String ? = nil ) {
115116
116- timer ? . invalidate ( )
117- timer = nil
117+ counter = 0
118+ ProgressHUD . showProgress ( status , counter / 100 )
118119
119- var intervalCount = 0.0
120- ProgressHUD . showProgress ( status, intervalCount/ 100 )
120+ timer = Timer . scheduledTimer ( withTimeInterval: 0.025 , repeats: true ) { [ weak self] _ in
121+ guard let self = self else { return }
122+ self . actionProgress ( status)
123+ }
124+ }
121125
122- timer = Timer . scheduledTimer ( withTimeInterval: 0.025 , repeats: true ) { [ self ] _ in
123- intervalCount += 1
124- ProgressHUD . showProgress ( status, intervalCount/ 100 )
125- if ( intervalCount >= 100 ) {
126- actionProgressStop ( status)
127- }
126+ //-------------------------------------------------------------------------------------------------------------------------------------------
127+ func actionProgress( _ status: String ? ) {
128+
129+ counter += 1
130+ ProgressHUD . showProgress ( status, counter/ 100 )
131+
132+ if ( counter >= 100 ) {
133+ actionProgressStop ( status)
128134 }
129135 }
130136
@@ -134,7 +140,7 @@ extension ViewController {
134140 timer? . invalidate ( )
135141 timer = nil
136142
137- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.3 ) {
143+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.25 ) {
138144 ProgressHUD . showSucceed ( status, interaction: false , delay: 0.75 )
139145 }
140146 }
@@ -213,22 +219,22 @@ extension ViewController {
213219// MARK: - UITableViewDelegate
214220//-----------------------------------------------------------------------------------------------------------------------------------------------
215221extension ViewController {
216-
222+
217223 //-------------------------------------------------------------------------------------------------------------------------------------------
218224 override func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
219-
225+
220226 tableView. deselectRow ( at: indexPath, animated: true )
221-
227+
222228 if ( indexPath. section == 0 ) && ( indexPath. row == 1 ) { view. endEditing ( true ) }
223229 if ( indexPath. section == 0 ) && ( indexPath. row == 2 ) { ProgressHUD . dismiss ( ) }
224230 if ( indexPath. section == 0 ) && ( indexPath. row == 3 ) { ProgressHUD . remove ( ) }
225-
231+
226232 if ( indexPath. section == 1 ) {
227233 if ( indexPath. row == 0 ) { ProgressHUD . show ( ) ; status = nil }
228234 if ( indexPath. row == 1 ) { ProgressHUD . show ( textShort) ; status = textShort }
229235 if ( indexPath. row == 2 ) { ProgressHUD . show ( textLong) ; status = textLong }
230236 }
231-
237+
232238 if ( indexPath. section == 2 ) {
233239 if ( indexPath. row == 0 ) { ProgressHUD . animationType = . none }
234240 if ( indexPath. row == 1 ) { ProgressHUD . animationType = . systemActivityIndicator }
@@ -244,27 +250,27 @@ extension ViewController {
244250 if ( indexPath. row == 11 ) { ProgressHUD . animationType = . circleStrokeSpin }
245251 ProgressHUD . show ( status)
246252 }
247-
253+
248254 if ( indexPath. section == 3 ) {
249255 if ( indexPath. row == 0 ) { actionProgressStart ( ) }
250256 if ( indexPath. row == 1 ) { actionProgressStart ( textShort) }
251257 if ( indexPath. row == 2 ) { actionProgressStart ( textLong) }
252258 }
253-
259+
254260 if ( indexPath. section == 4 ) {
255261 if ( indexPath. row == 0 ) { ProgressHUD . showProgress ( 0.1 , interaction: true ) }
256262 if ( indexPath. row == 1 ) { ProgressHUD . showProgress ( 0.4 , interaction: true ) }
257263 if ( indexPath. row == 2 ) { ProgressHUD . showProgress ( 0.6 , interaction: true ) }
258264 if ( indexPath. row == 3 ) { ProgressHUD . showProgress ( 0.9 , interaction: true ) }
259265 }
260-
266+
261267 if ( indexPath. section == 5 ) {
262268 if ( indexPath. row == 0 ) { ProgressHUD . showSuccess ( ) }
263269 if ( indexPath. row == 1 ) { ProgressHUD . showSuccess ( textSuccess) }
264270 if ( indexPath. row == 2 ) { ProgressHUD . showError ( ) }
265271 if ( indexPath. row == 3 ) { ProgressHUD . showError ( textError) }
266272 }
267-
273+
268274 if ( indexPath. section == 6 ) {
269275 if ( indexPath. row == 0 ) { ProgressHUD . showSucceed ( ) }
270276 if ( indexPath. row == 1 ) { ProgressHUD . showSucceed ( textSucceed) }
@@ -273,7 +279,7 @@ extension ViewController {
273279 if ( indexPath. row == 4 ) { ProgressHUD . showAdded ( ) }
274280 if ( indexPath. row == 5 ) { ProgressHUD . showAdded ( textAdded) }
275281 }
276-
282+
277283 if ( indexPath. section == 7 ) {
278284 if ( indexPath. row == 0 ) { ProgressHUD . show ( randomText ( ) , icon: . heart) }
279285 if ( indexPath. row == 1 ) { ProgressHUD . show ( randomText ( ) , icon: . doc) }
@@ -296,7 +302,7 @@ extension ViewController {
296302 if ( indexPath. row == 18 ) { ProgressHUD . show ( randomText ( ) , icon: . search) }
297303 }
298304 }
299-
305+
300306 //-------------------------------------------------------------------------------------------------------------------------------------------
301307 func randomText( ) -> String ? {
302308
0 commit comments