Last active
March 2, 2016 15:13
-
-
Save giulio92/1b53e9d33e78d0e6d2d6 to your computer and use it in GitHub Desktop.
Manage multiple networkActivityIndicator(s) just by calling a single function and passing a BOOL, the function will take care of the rest. Simple and easy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var networkActivityIndicatorCount = 0 | |
func setNetworkActivityIndicatorVisible(visible:Bool) { | |
if visible { | |
networkActivityIndicatorCount++ | |
} else { | |
networkActivityIndicatorCount-- | |
} | |
if networkActivityIndicatorCount < 0 { | |
networkActivityIndicatorCount = 0 | |
} | |
UIApplication.sharedApplication().networkActivityIndicatorVisible = networkActivityIndicatorCount > 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func taskStarted() { | |
(UIApplication.sharedApplication().delegate as! AppDelegate).setNetworkActivityIndicatorVisible(true) | |
} | |
func taskEnded() { | |
(UIApplication.sharedApplication().delegate as! AppDelegate).setNetworkActivityIndicatorVisible(false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment