I have managed to create a UIActivityIndicatorView extension for turning animating it to start and stop. However I would like make it better by using a computed property of type bool using a get and set. I have tried but can't think of way to do it. How could I refactor this.
extension UIActivityIndicatorView {
func loadingIndicator(_ isLoading: Bool) {
if isLoading {
self.startAnimating()
} else {
self.stopAnimating()
}
}
}
You can use the
isAnimatingproperty ofUIActivityIndicatorViewas the backing value forisLoading. You just need to make sure that you control starting/stopping the animation correctly in the setter, that will setisAnimatingand as a result,isLoadingwill also get set correctly.