Temporarily saving a photo
To start, we will concern ourselves with how to temporarily store our pictures in memory. To do this, we can add an image array as a property of our view controller:
class ViewController: UIViewController { var photos = [UIImage]() // ... }
As we saw in the image picker delegate method, UIKit
provides us a UIImage
class that can represent images. Our photos property can store an array of these instances. This means that the first step for us is to add new images to our property when the callback is called:
func imagePickerController( picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]! ) { self.photos.append(image) self.dismissViewControllerAnimated(true, completion: nil) }
Now, every time the user takes or picks a new photo, we add it to our list, which stores all the images in the memory. However, this isn't quite enough, as we also...