Question: What is the the imageWasSavedSuccessfully function?

Transcript – Question: What is the the imageWasSavedSuccessfully function?

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.

Question: What is the the imageWasSavedSuccessfully function?

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.

Steps to access camera

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.

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!

Great videos. Better emails.

Have the latest videos emailed to you every month! This way you’ll never miss an important video.

Related Posts

Tools Used

Swift

Xcode

iOS



Media Credits

All media created and owned by DJ Spiess unless listed below.

No infringement intended

Music: Funk Down – Free audio on YouTube.com

Get the code

The source code for “Question: What is the the imageWasSavedSuccessfully function?” can be found on Github. If you have Git installed on your system, you can clone the repository by issuing the following command:

Don't miss another video!

New videos come out every week. Make sure you subscribe!

Comments

comments

DJ Spiess

Your personal instructor

My name is DJ Spiess and I'm a developer with a Masters degree in Computer Science working in Colorado, USA. I primarily work with Java server applications. I started programming as a kid in the 1980s, and I've programmed professionally since 1996. My main focus are REST APIs, large-scale data, and mobile development. The last six years I've worked on large National Science Foundation projects. You can read more about my development experience on my LinkedIn account.