title: IOS Save image with name
body: <p>i have an app that takes a picture and merges it with another image. I want to be able to display al the images taken in the app (and only my app) and display them in a gallery view. the problem I am having is in assigning the image a name.</p>
  
  <p>I have tried a number of different ways</p>
  
  <p><strong>First Attempt</strong></p>
  
  <pre><code>UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)
  </code></pre>
  
  <p>this saved the image but i do not know how i can retrieve it</p>
  
  <p><strong>Second Attempt</strong></p>
  
  <pre><code>PHPhotoLibrary.sharedPhotoLibrary().performChanges({
      let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(newImage)
  
      }, completionHandler: { (success, error) -&gt; Void in
          if success {
              //image saved to photos library.
              print("image saved")
          }
  });
  </code></pre>
  
  <p>Same Problem as first attempt</p>
  
  <p><strong>Third Attempt</strong></p>
  
  <pre><code>let date :NSDate = NSDate()
  
  let dateFormatter = NSDateFormatter()
  dateFormatter.dateFormat = "yyyy-MM-dd'_'HH:mm:ss"
  dateFormatter.timeZone = NSTimeZone(name: "GMT")
  
  let imageName = "\(dateFormatter.stringFromDate(date)).jpg"
  
  //var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)
  var documentsDirectoryPath = getDocumentsURL().relativePath
  documentsDirectoryPath! += imageName
  
  let settingsData: NSData = UIImageJPEGRepresentation(newImage, 1.0)!
  settingsData.writeToFile(documentsDirectoryPath!, atomically: true)
  </code></pre>
  
  <p>This seems to have the most promise but the file does bot save</p>
  
  <p>I have looked at various answers on here but I still cant identify a solution</p>