Saving and Loading Images, Swift 2.0

Swift 2.0 , Xcode 7.1.1

This will show you how to save and load images in a way that is very easy and straight forward.
Here is the function to save your image first.
We’ll assume you already have an UIImageView, containing an image, named ‘image’ :

Here is how to use the function later in your code:

However before you can Save or Load anything you have to know the ‘path’ you are going to use.
We’ll need 3 things:

      • a function to pinpoint the documents directory
      • a function to pinpoint a file in the documents directory
      • a variable to store the location ( path ) of the image we want to save

Here is how we are going to do that:

Make sure the 2 functions above are placed before the class declaration. For example, before:

At this point you already have the image saved to the documents folder inside your app folder.
Keep in mind that folder will keep changing when using the IOS Simulator.

Here is how to declare the function for loading an image from a Path:

Now we can use that function and load our image and
apply it to an imageView you might have for an example:

Here is how the full example should look: