I am making a loading icon in my extension.swift file. I believe we do not need to use any third party library just for loading icons. However I cant store any values in the extension file. If I didnt store, it will look like
import UIKit
extension UIViewController {
func startLoading() {
let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.style = .gray
DispatchQueue.main.async {
self.view.addSubview(activityIndicator)
}
activityIndicator.startAnimating()
UIApplication.shared.beginIgnoringInteractionEvents()
}
func stopLoading() {
let activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
DispatchQueue.main.async {
activityIndicator.stopAnimating()
}
UIApplication.shared.endIgnoringInteractionEvents()
}
}
So in your view controller, you can directly call startLoading() or stopLoading(). However the stopLoading doesnt work. It is because it's not accessing the variable initiated by startLoading. Any ways to go about this? Thanks alot guys!