# Save image to file system

**URL:** <https://forums.kodeco.com/t/save-image-to-file-system/29944>\
**Category:** iOS\
**Created:** [May 20, 2017, 1:18pm UTC](https://forums.kodeco.com/t/save-image-to-file-system/29944 "2017-05-20T13:18:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stas](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stas/32/67675_2.png) [@stas](https://forums.kodeco.com/u/stas)\
**Post date:** [May 20, 2017, 1:18pm UTC](https://forums.kodeco.com/t/save-image-to-file-system/29944/1 "2017-05-20T13:18:40Z")

</div>

Hi! At main.storyboard I have UIImageView and button. I want to save my image witch I took via camera to file system. But when I loading my app again, this image disappeared. Tell me please what I done wrong? This is my code:

> import UIKit

> class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

> ```
> @IBAction func useCamera(_ sender: UIButton) {
> 
> ```

> ```
> let picker = UIImagePickerController()
> picker.sourceType = .camera
> 
> ```

> ```
> self.present(picker, animated: true, completion: nil)
> picker.delegate = self
> }
> 
> ```

> ```
> @IBOutlet weak var imageView: UIImageView!
> 
> ```

> ```
> override func viewDidLoad() {
> super.viewDidLoad()
> // Do any additional setup after loading the view, typically from a nib.
> }
> 
> ```

> ```
> override func didReceiveMemoryWarning() {
> super.didReceiveMemoryWarning()
> // Dispose of any resources that can be recreated.
> }
> 
> ```

> ```
> func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
> 
> ```

> ```
> imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
> picker.dismiss(animated: true, completion: nil)
> 
> ```

> ```
> if imageView.image == UIImage(named: "example.jpg") {
> if let data = UIImageJPEGRepresentation(imageView.image!, 0.8) {
> let filename = getDocumentsDirectory().appendingPathComponent("copy.png")
> try? data.write(to: filename)
> }
> }
> }
> 
> ```

> ```
> func getDocumentsDirectory() -> URL {
> let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
> let documentsDirectory = paths[0]
> return documentsDirectory
> }
> 
> ```
> 
> }

---

<div class="post-metadata">

**Author:** ![rcasey](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcasey/32/82229_2.png) [@rcasey](https://forums.kodeco.com/u/rcasey)\
**Post date:** [May 22, 2017, 3:30pm UTC](https://forums.kodeco.com/t/save-image-to-file-system/29944/3 "2017-05-22T15:30:47Z")

</div>

In your useCamera function, you need to set the picker’s delegate before presenting it.
