Make it easier to track the loading status of your objects.
v0.7.0
Transform this:
class LameViewController: UIViewController
{
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView?
private var isPerformingVeryLongBackgroundTask = false
func performVeryLongBackgroundTask() {
self.isPerformingVeryLongBackgroundTask = true
self.activityIndicatorView?.startAnimating()
doStuff { [weak self] _ in
if self?.isPerformingOtherVeryLongBackgroundTask == false {
self?.activityIndicatorView?.stopAnimating()
}
self?.isPerformingVeryLongBackgroundTask = false
}
}
private var isPerformingOtherVeryLongBackgroundTask = false
func performOtherVeryLongBackgroundTask() {
self.isPerformingOtherVeryLongBackgroundTask = true
self.activityIndicatorView?.startAnimating()
doOtherStuff { [weak self] _ in
if self?.isPerformingVeryLongBackgroundTask == false {
self?.activityIndicatorView?.stopAnimating()
}
self?.isPerformingOtherVeryLongBackgroundTask = false
}
}
}
Into this:
class CoolViewController: UIViewController, UILoader
{
func didChangeLoadingStatus(_ loading: Bool) {
if loading {
//if you have a `UIActivityIndicatorView`, it will automatically start animating
//disable buttons
//do all sorts of stuff to your UI while you're loading things
} else {
//stop loading!
//get on with your life
}
}
//optional
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView?
func performVeryLongBackgroundTask() {
self.isLoading = true
doStuff { [weak self] _ in
self?.isLoading = false
}
}
func performOtherVeryLongBackgroundTask() {
self.isLoading = true
doOtherStuff { [weak self] _ in
self?.isLoading = false
}
}
}
iOS 9.0+ Swift 3.2
Because of this, I've dropped support for Cocoapods on this repo. I cannot have production code rely on a dependency manager that breaks this badly.
Why submodules, you ask?
Following this thread and other similar to it, and given that Cocoapods only works with Swift by adding the use_frameworks! directive, there's a strong case for not bloating the app up with too many frameworks. Although git submodules are a bit trickier to work with, the burden of adding dependencies should weigh on the developer, not on the user. 😉
To install Backgroundable using git submodules:
cd toYourProjectsFolder
git submodule add -b submodule --name UILoader https://github.com/BellAppLab/UILoader.git
Swift 2 support
git submodule add -b swift2 --name UILoader https://github.com/BellAppLab/UILoader.git
Then, navigate to the new Backgroundable folder and drag the Source
folder into your Xcode project.
Bell App Lab, apps@bellapplab.com
Backgroundable is available under the MIT license. See the LICENSE file for more info.