title: extension for keyboard show notification iOS
body: <p>I'm using this code. if keyboard appears then it increases the size of the view so user can easily scroll to the bottom. everything works fine but I want to make an extension for this code because I don't want to use such a long code in my controller </p>
  
  <pre><code>import UIKit
  
      extension UIViewController {
  
  
          func hideKeyboardWhenTappedAround() {
              let tap: UITapGestureRecognizer =     UITapGestureRecognizer(target: self, action:    #selector(dismissKeyboard))
              tap.cancelsTouchesInView = false
              view.addGestureRecognizer(tap)
          }
  
  
          @objc func dismissKeyboard() {
              view.endEditing(true)
          }
  
          func setnotification()
          {
  
              NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown), name: UIResponder.keyboardWillShowNotification, object: nil)
              NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
          }
  
          @objc func keyboardWasShown(notification: NSNotification)
          {
  
              var info = notification.userInfo!
              let keyboardSize = (info[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
              let contentInsets : UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize!.height+10, right: 0.0)
              self.scrolView.contentInset = contentInsets
              self.scrolView.scrollIndicatorInsets = contentInsets
              var aRect : CGRect = self.view.frame
              aRect.size.height -= keyboardSize!.height
              if let activeField =  activeTextField
              {
                  if (!aRect.contains(activeField.frame.origin))
                  {
                     self.scrolView.scrollRectToVisible(activeField.frame, animated: true)
                  }
              }
          }
          // when keyboard hide reduce height of scroll view
          @objc func keyboardWillBeHidden(notification: NSNotification){
              let contentInsets : UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0,bottom: 0.0, right: 0.0)
              myScrolView!.contentInset = contentInsets
              myScrolView!.scrollIndicatorInsets = contentInsets
              self.view.endEditing(true)
          }
  }
  </code></pre>