Skip to content

Instantly share code, notes, and snippets.

@giulio92
Last active March 2, 2016 15:13
Show Gist options
  • Save giulio92/1b53e9d33e78d0e6d2d6 to your computer and use it in GitHub Desktop.
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.
var networkActivityIndicatorCount = 0
func setNetworkActivityIndicatorVisible(visible:Bool) {
if visible {
networkActivityIndicatorCount++
} else {
networkActivityIndicatorCount--
}
if networkActivityIndicatorCount < 0 {
networkActivityIndicatorCount = 0
}
UIApplication.sharedApplication().networkActivityIndicatorVisible = networkActivityIndicatorCount > 0
}
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