title: How can I save a picture in the Photo Library Swift?
body: <p>I am Swift beginner and just completed my Photo camera function in my app. The problem which I have now is that when I take a photo from the camera, it is not saved into the photo library on my iPhone. Everything works perfectly I am able to take pictures, but when I check in Photos, it seems that they are not saved.
  I had checked for similar questions, but I haven't found a proper answer, I see that they are people who add buttons to access the photo library directly but I do not need such a button. The only function, I require is taking a picture and when the user clicks select photo to save it in the Photos.</p>
  
  <p>So far I have used this:</p>
  
  <pre><code>class ViewController: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate{
  
  
  
   let imagePicker: UIImagePickerController! = UIImagePickerController()
  
     override func viewDidLoad() {
  
      super.viewDidLoad()
  
      imagePicker.delegate = self
  
      let upSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes))
  
      upSwipe.direction = .up
  
      view.addGestureRecognizer(upSwipe)
  
  }
  </code></pre>
  
  <p>and the function:</p>
  
  <pre><code>func handleSwipes(sender:UISwipeGestureRecognizer) {
  
          if (sender.direction == .up){
  
              if ( UIImagePickerController.isSourceTypeAvailable(.camera)){
  
  
  
                  if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
                      imagePicker.allowsEditing = false
                      imagePicker.sourceType = .camera
                      imagePicker.cameraCaptureMode = .photo
                      present(imagePicker,animated: true, completion: {})
         }
              }
  </code></pre>
  
  <p>Here is what I get on my iPhone: I only want when the user chooses to use the photo, the photo itself to be saved in the gallery, as simple as that.
  <a href="https://i.stack.imgur.com/tbSnR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tbSnR.jpg" alt="enter image description here"></a></p>