# MyLocations - Changing Photo Not Does Not Update Photo

**URL:** <https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331>\
**Category:** iOS Apprentice\
**Created:** [May 6, 2017, 6:39pm UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331 "2017-05-06T18:39:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![savagej](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/savagej/32/95769_2.png) [@savagej](https://forums.kodeco.com/u/savagej)\
**Post date:** [May 6, 2017, 6:39pm UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/1 "2017-05-06T18:39:27Z")

</div>

I have completed the MyLocations app all the way through the Photo Picker section, yet when I try to change the photo for my location, this change is not reflected.

Other related functions seem to work fine. I can add and delete photos and this is reflected in the documents directory and SQL database.

Here is my project on GitHub:

> **[My-Locations/MyLocations at master · Pigpocket/My-Locations](https://github.com/Pigpocket/My-Locations/tree/master/MyLocations)**
>
> master/MyLocations

Help!

---

<div class="post-metadata">

**Author:** ![savagej](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/savagej/32/95769_2.png) [@savagej](https://forums.kodeco.com/u/savagej)\
**Post date:** [May 9, 2017, 3:40am UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/2 "2017-05-09T03:40:54Z")

</div>

C’mon guys. Dying over here.

---

<div class="post-metadata">

**Author:** ![hollance](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hollance/32/109009_2.png) [@hollance](https://forums.kodeco.com/u/hollance)\
**Post date:** [May 9, 2017, 7:14am UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/3 "2017-05-09T07:14:36Z")

</div>

What do you mean exactly by “this change is not reflected”? What doesn’t happen and what did you expect to happen instead?

---

<div class="post-metadata">

**Author:** ![savagej](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/savagej/32/95769_2.png) [@savagej](https://forums.kodeco.com/u/savagej)\
**Post date:** [May 9, 2017, 5:17pm UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/4 "2017-05-09T17:17:43Z")

</div>

Hey Matthijs!

When I try to change the image for a location in the Location Details View Controller, the image will change on the Location Details View Controller immediately. However, when I back out to the Locations View Controller, the image has not updated. And when I go back into the Location Details View Controller, the image has reverted to the original image. Hopefully that’s enough information? Let me know, if not.

I put a link to my GitHub project in my first post. The app is otherwise completed except for this problem. Thank you, a great learning experience!

Savage

---

<div class="post-metadata">

**Author:** ![hollance](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hollance/32/109009_2.png) [@hollance](https://forums.kodeco.com/u/hollance)\
**Post date:** [May 11, 2017, 8:10am UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/5 "2017-05-11T08:10:16Z")

</div>

Sorry for the slow reply. In your LocationDetailsViewController, inside done(), the following happens:

```auto
        if let image = image {
            if !location.hasPhoto {
                location.photoID = Location.nextPhotoID() as NSNumber
                if let data = UIImageJPEGRepresentation(image, 0.5) {
                    do {
                        try data.write(to: location.photoURL, options: .atomic)
                    } catch {
                        print("Error while writing file: \(error)")
                    }
                }
            }
        }

```

However, it should look like this:

```auto
    if let image = image {
      if !location.hasPhoto {
        location.photoID = Location.nextPhotoID() as NSNumber
      }
      if let data = UIImageJPEGRepresentation(image, 0.5) {
        do {
          try data.write(to: location.photoURL, options: .atomic)
        } catch {
          print("Error writing file: \(error)")
        }
      }
    }

```

Spot the differences. 😃

---

<div class="post-metadata">

**Author:** ![savagej](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/savagej/32/95769_2.png) [@savagej](https://forums.kodeco.com/u/savagej)\
**Post date:** [May 11, 2017, 7:59pm UTC](https://forums.kodeco.com/t/mylocations-changing-photo-not-does-not-update-photo/29331/6 "2017-05-11T19:59:26Z")

</div>

OF COURSE. Ugh.

I thought I was done with braces at 15, but now I can see they will haunt me forever.

Thanks Matthijs!
