In this video, we’ll take a quick look at the Swift method imageWasSavedSuccessfully
when taking pictures with our iOS camera.
Hi, I’ve been getting many questions in the comments, so I figure it’s time we start
answering some in their own videos.
In the “How to access the iOS camera using Swift 2.0”, 00bikeboy asks “The transcript
doesn’t go into the imageWasSavedSuccessfully function.
Any chance you could go over this part of the code?”
Absolutely!
Let’s take a deeper look at the method.
If you remember from the Swift iOS camera tutorial, these were the basic steps to taking
a photo.
We get access, check to see if we can use the camera, present a camera view controller,
check to see if we have an image, and then do something with it.
The area we’re focusing on for this question is what we do with the image.
What we did in the video was save the image to the photos album.
iOS calls didFinishPickingMediaWithInfo once we have selected a photo, either by selection
or taking a photo.
We then called UIImageWriteToSavedPhotosAlbum.
This saves the photo to the photo album, and from there we can provide another function
to call once the image is written.
The selector is imageWasSavedSuccessfully.
This is a user defined function, and we can put anything we want into it.
What we put in the function was a check to make sure it was successfully saved.
If it didn’t we’d get an error object.
If not, the image was saved so I’m updating the UI to display the image on a background
thread.
So that’s what we were doing in the imageWasSavedSuccessfully selector.
To recap, it’s a user defined selector we passed to UIImageWriteToSavedPhotosAlbum.
The method can do anything we want, but in our case we just updated the UI with the new
image.
If you have any other questions about this video, or any others, leave a comment below
or you can also post questions on DeegeU.com.
If you want to keep up to date with the latest DeegeU tutorials, make sure you subscribe
to the YouTube channel, like the DeegeU Facebook page, or sign up for the DeegeU.com newsletter.
See you in the next video!