title: Swift: starting and stopping the animation of an activity indicator inside a custom class
body: <p>I want to put an activity indicator inside a custom class so I can start/stop it from any view controller.</p>
  
  <p>The below code works when starting the activity indicator but not stopping, how can I do this?</p>
  
  <pre><code>static func activityIndicatorFunction(view: UIView, targetVC: UIViewController, animate: Bool) {
  
      var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  
      if animate == false {
          activityIndicator.stopAnimating()
          UIApplication.shared.endIgnoringInteractionEvents()
      } else {
          activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
          activityIndicator.backgroundColor = UIColor(red:0.16, green:0.17, blue:0.21, alpha:1)
          activityIndicator.layer.cornerRadius = 6
          activityIndicator.center = targetVC.view.center
          activityIndicator.hidesWhenStopped = true
          activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
          view.addSubview(activityIndicator)
          activityIndicator.startAnimating()
          //UIApplication.shared.beginIgnoringInteractionEvents()
      }
  }
  </code></pre>
  
  <p><strong>An example of starting the activity indicator</strong>, the animate parameter would be false if I wanted to stop it.</p>
  
  <pre><code>Utils.activityIndicatorFunction(view: view, targetVC: self, animate: true)
  </code></pre>