I found a way to display activity Indicator with minimum code:
first of all import your UI Kit
import UIKit;
Then you have to initiate activity indicator
let activityIndicator:UIActivityIndicatorView = UIActivityIndicatorView();
Then just copy paste this functions below which are self explainatory and call them whereever you need them:
func startLoading(){
activityIndicator.center = self.view.center;
activityIndicator.hidesWhenStopped = true;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray;
view.addSubview(activityIndicator);
activityIndicator.startAnimating();
UIApplication.shared.beginIgnoringInteractionEvents();
}
func stopLoading(){
activityIndicator.stopAnimating();
UIApplication.shared.endIgnoringInteractionEvents();
}