Group Group Group Group Group Group Group Group Group

Chapter 12 - Photography - Regarding saving and passing the photo data

#1

Hi,

First of all, thank you for the great chapter!

My question is, how can I save the main image data into a UIImage and then pass the image data to the next view controller through prepare(for segue:) so that I can do something more than just saving in the Photo Library with it?

I attempted to do this by doing the following:

Step 1) Added these in the PhotoCaptureDelegate.swift file:

  • ‘var photoTaken: UIImage?’ and
  • ‘let photoTaken = UIImage(data: photoData)’ in func capture( … didFinishCaptureForResolvedSettings: ) {…},

Step 2) And then, added these in the the CameraViewController.swift file:

  • ‘var lastUniqueID: Int64?’
  • ‘self.lastUniqueID = uniqueID’ in func capturePhoto() {…} and
  • ’ if let photo = self.photoCaptureDelegates[lastUniqueID!]?.photoTaken as UIImage? {
    self.photoCaptured = photo
    } else {
    return
    }
    in func prepare(for segue: ).

Unfortunately, this attempt wasn’t successful because the performSegue function was called BEFORE the capture( … didFinishCaptureForResolvedSettings: ) function was called, so the photoTaken variable ended up being always nil.

Thanks for your help in advance. Please let me know if you need any clarification!

Jay