From fb27aa9af248e107681315ba3f2b061b79922fd6 Mon Sep 17 00:00:00 2001 From: Paul Cantrell Date: Thu, 8 Mar 2018 18:46:34 -0600 Subject: [PATCH] Revert "Merge pull request #238 from Narsail/master" c4eca466c438fd3e38530b9488ccf8b2e5585619 --- .../SiestaUI/NetworkActivityIndicator.swift | 96 +++++++++---------- 1 file changed, 46 insertions(+), 50 deletions(-) diff --git a/Source/SiestaUI/NetworkActivityIndicator.swift b/Source/SiestaUI/NetworkActivityIndicator.swift index 0f903ab4..ad2d8e09 100644 --- a/Source/SiestaUI/NetworkActivityIndicator.swift +++ b/Source/SiestaUI/NetworkActivityIndicator.swift @@ -6,62 +6,58 @@ // Copyright © 2016 Bust Out Solutions. All rights reserved. // -#if UIApplication - #if !COCOAPODS - import Siesta - #endif - import UIKit +#if !COCOAPODS + import Siesta +#endif +import UIKit - // Tracks the number of requests in progress across all Siesta services - private var requestsInProgress = 0 +// Tracks the number of requests in progress across all Siesta services +private var requestsInProgress = 0 + { + didSet { - didSet - { - - UIApplication.shared.isNetworkActivityIndicatorVisible = - requestsInProgress > 0 - - } + UIApplication.shared.isNetworkActivityIndicatorVisible = + requestsInProgress > 0 } - - private func requestStarted() - { requestsInProgress += 1 } - - private func requestCompleted() - { requestsInProgress -= 1 } - - extension Configuration + } + +private func requestStarted() + { requestsInProgress += 1 } + +private func requestCompleted() + { requestsInProgress -= 1 } + +extension Configuration + { + /** + Causes requests to automatically show and hide the iOS network activity indicator. You can attach this to an + entire service: + + service.configure { + $0.useNetworkActivityIndicator() + } + + …or only to carefully selected large resources, if you are looking to follow [Apple’s Human Interface guidelines + for the indicator](https://developer.apple.com/ios/human-interface-guidelines/ui-controls/progress-indicators/#network-activity-indicators): + + service.configure("/downloads/​**") { + $0.useNetworkActivityIndicator() + } + service.configure("/profile/avatar", requestMethods: [.post, .put]) { + $0.useNetworkActivityIndicator() + } + */ + public mutating func useNetworkActivityIndicator() { - /** - Causes requests to automatically show and hide the iOS network activity indicator. You can attach this to an - entire service: - - service.configure { - $0.useNetworkActivityIndicator() - } - - …or only to carefully selected large resources, if you are looking to follow [Apple’s Human Interface guidelines - for the indicator](https://developer.apple.com/ios/human-interface-guidelines/ui-controls/progress-indicators/#network-activity-indicators): - - service.configure("/downloads/​**") { - $0.useNetworkActivityIndicator() - } - service.configure("/profile/avatar", requestMethods: [.post, .put]) { - $0.useNetworkActivityIndicator() - } - */ - public mutating func useNetworkActivityIndicator() + decorateRequests { - decorateRequests - { - resource, request in + resource, request in - requestStarted() - request.onCompletion - { _ in requestCompleted() } + requestStarted() + request.onCompletion + { _ in requestCompleted() } - return request - } + return request } } -#endif + }