title: How to save UIImage from UIImagePicker in Documents folder and get string for path to save in Core Data in Swift
body: <p>I'm building my first Swift application. In it, the user needs to be able to choose an image from the iPhone's photo library. Then I want to save this image to keep permanently for use in other parts of the app. </p>
  
  <p>I know it is possible to convert a <code>UIImage</code> to <code>NSData</code> and save as binary data in Core Data, but I have read that it is a bad idea to store Binary Large Objects, such as images directly in Core Data.</p>
  
  <p>I have seen it suggested that you should save the image file in the Documents folder and then just save a string for the file path in Core Data. But I haven't seen an actual example of the code snippet needed to do this. </p>
  
  <p>Steps to accomplish:</p>
  
  <ol>
  <li>get <code>UIImage</code> from image picker. (this part I've got working) </li>
  <li>save the image data in Documents folder</li>
  <li>get string value for the file path to Documents folder</li>
  <li>save this string in Core Data</li>
  <li>Do steps 2-4 in reverse elsewhere in the app to use the stored
  image.</li>
  </ol>
  
  <p>Here is the code for the <code>UIImagePicker</code> that I'm starting with:</p>
  
  <pre><code>@IBAction func openImagePicker(sender: AnyObject) {
      if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
          imagePicker.delegate = self
          imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
          imagePicker.allowsEditing = false
          self.presentViewController(imagePicker, animated: true, completion: nil)
      }
  }
  
  func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!)
  {
  self.dismissViewControllerAnimated(true, completion: nil)
  myImageView.image = image
  }
  </code></pre>
  
  <p>So the <code>UIImage</code> displayed in <code>myImageView</code>.image is what I need to do something with.</p>