Q:

how i can add an activity indicator to an image that uses tap gesture recognizer

i want to know how i can add an activity indicator to an image that uses tap gesture recognizer if the user tap the image it's take too long to load like the app not responding i can't know in code how to add this acton and when the user is tapped the pic  
this is tap gesture code 
     override func viewDidLoad() {
            super.viewDidLoad()

    profileImage.layer.cornerRadius = profileImage.frame.size.width/2
            profileImage.clipsToBounds = true
            profileImage.contentMode = .scaleAspectFill
            let tapGestur = UITapGestureRecognizer(target: self, action: #selector(SignupVC.selectProfileImage))
            profileImage.addGestureRecognizer(tapGestur)
            profileImage.isUserInteractionEnabled = true
    }

 @objc func selectProfileImage() {
        let pickerController = UIImagePickerController()
        pickerController.delegate = self
        PiActivityIndicator.startAnimating()
        present(pickerController, animated: true, completion: nil)
        pickerController.allowsEditing = true

    }

    extension SignupVC: UINavigationControllerDelegate,UIImagePickerControllerDelegate {

        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

            if let image = info["UIImagePickerControllerOriginalImage"] as? UIImage {
                selectedImage = image
                profileImage.image = image
                self.profileActivityIndicator.startAnimating()

            }

            dismiss(animated: true, completion: nil)
        }
    }

A:

Here I am using a imagePicker and a Indicator from storyBoard 
Instead of Gesture used a button Action 
Issue is to show activity indicator till image picker loading time 
use below code for Reference 
import UIKit

class ProfileViewController: UIViewController,UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    @IBOutlet weak var profileImageView: UIImageView!

    @IBOutlet weak var Spinner: UIActivityIndicatorView!

    override func viewDidLoad() {
        super.viewDidLoad()

        Spinner.isHidden = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func imageSelectAction(_ sender: Any) {
        //your tap gesture action like 
        //show and start animating spinner 
        //animate till output is not achieved 
        Spinner.isHidden = false
        self.Spinner.startAnimating()

        //Initiate a picker here 
        let picker = UIImagePickerController()
        //Delegates
        picker.delegate = self
        picker.allowsEditing = true
        //present to call imagePickerController delegate function
        present(picker, animated: true, completion: nil)
    }

    //delegate method
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        //selected image from picker
        var selectedImageFromPicker: UIImage?
        //additional checks if required 
        if let editedImage = info["UIImagePickerControllerEditedImage"] as? UIImage
        {
            selectedImageFromPicker = editedImage
        }
        else if let originalImage = info["UIImagePickerControllerOriginalImage"] as? UIImage
        {

            selectedImageFromPicker = originalImage
        }

        //here set value in your outlet profile image 
        if let selectedImage = selectedImageFromPicker
        {
            profileImageView.image = selectedImage
        }

        //Hide spinner and stop animating
        Spinner.isHidden = true
        self.Spinner.stopAnimating()
        dismiss(animated: true, completion: nil)

    }

    //if picker is cancelled in any case without selection
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        print("canceled picker")
        //if picker is cancelled so need to hide animating spinner
        Spinner.isHidden = true
        self.Spinner.stopAnimating()
        dismiss(animated: true, completion: nil)
    }
}

can also make use of TapGesture for ease I used a button , just add my button action code in your tap gesture and start spinner in tap gesture 
and hide animating spinner in picker delegates 

