# MyLocations Exercise page 220 help

**URL:** <https://forums.kodeco.com/t/mylocations-exercise-page-220-help/16160>\
**Category:** iOS Apprentice\
**Created:** [June 20, 2016, 3:56am UTC](https://forums.kodeco.com/t/mylocations-exercise-page-220-help/16160 "2016-06-20T03:56:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dukerulz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dukerulz/32/81494_2.png) [@dukerulz](https://forums.kodeco.com/u/dukerulz)\
**Post date:** [June 20, 2016, 3:56am UTC](https://forums.kodeco.com/t/mylocations-exercise-page-220-help/16160/1 "2016-06-20T03:56:37Z")

</div>

Trying the exercise in MyLocations, to use NSNotification object to help make a more efficient way of reloading locations after any changes. Here’s the code after looking at others’ ideas, but no solutions. I don’t get any errors, but when I add a location it never appears on the map, and when I delete a location it doesn’t disappear. In fact, it appears to leave an item in the data store which has no name or description and a lat/lon 0f 0.00000/0.00000. If I stop the app and restart, then the pins disappear. Self.updateLocations is commented out since that would seem to defeat the purpose of the exercise.

var managedObjectContext: NSManagedObjectContext! {

```
    didSet {
        NSNotificationCenter.defaultCenter().addObserverForName(NSManagedObjectContextObjectsDidChangeNotification, object: managedObjectContext, queue: NSOperationQueue.mainQueue()) { notification in
            if self.isViewLoaded() {
                // self.updateLocations()
                
                if let dictionary = notification.userInfo {
                    print(dictionary["inserted"])
                    print(dictionary["deleted"])
                    print(dictionary["updated"])
                    
                    if let locations = dictionary["inserted"] as? Set<Location> {
                        for location in locations {
                            self.mapView.addAnnotation(location)
                        }
                    if let locations = dictionary["deleted"] as? Set<Location> {
                        for location in locations {
                            self.mapView.removeAnnotation(location)
                            }
                        }
                    if let locations = dictionary["updated"] as? Set<Location> {
                        for location in locations {
                            self.mapView.removeAnnotation(location)
                            self.mapView.addAnnotation(location)
                            }
                        }
                    }
                }
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![dukerulz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dukerulz/32/81494_2.png) [@dukerulz](https://forums.kodeco.com/u/dukerulz)\
**Post date:** [June 22, 2016, 5:12pm UTC](https://forums.kodeco.com/t/mylocations-exercise-page-220-help/16160/2 "2016-06-22T17:12:01Z")

</div>

As an update, I was missing a closing bracket. That partially solved the problem. However, now when I add a new location, it shows up on the map in the proper location, but the disclosure button shows only a blank location.
