             return self.workoutLog!.workout.exercises.array as! [Exercise]
         }
     }
+    var imageURL: NSURL!
+    var workoutImage: UIImage!
+    let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
+    let tempImageName = "temp_image.jpg"
+    
     
     override func viewDidLoad()
     {

    }
}

extension LoggingViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    func pickPhoto() {
        if UIImagePickerController.isSourceTypeAvailable(.SavedPhotosAlbum) {

        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = .Camera
        imagePicker.cameraCaptureMode = .Photo
        imagePicker.modalPresentationStyle = .FullScreen
        
        presentViewController(imagePicker, animated: true, completion: nil)
    }
    
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        workoutImage = info[UIImagePickerControllerOriginalImage] as? UIImage
        saveImageLocally(info)
        savePhoto()
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func saveImageLocally(info: [String : AnyObject]) {
        let imageData: NSData = UIImageJPEGRepresentation(workoutImage, 0.8)!
        let path = documentsDirectoryPath.stringByAppendingPathComponent(tempImageName)
        imageURL = NSURL(fileURLWithPath: path)
        imageData.writeToURL(imageURL, atomically: true)
    }
    
    func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
        if error == nil {
            let ac = UIAlertController(title: "Saved!", message: "Your image has been saved to your photos.", preferredStyle: .Alert)
            ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            presentViewController(ac, animated: true, completion: nil)
        } else {
            let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
            ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            presentViewController(ac, animated: true, completion: nil)
        }
    }
    
    func savePhoto(){
        UIImageWriteToSavedPhotosAlbum(workoutImage, self, "image:didFinishSavingWithError:contextInfo:", nil)
    }
}
