I want to observe changes to the Calendar application so I register for the EKEventStoreChangedNotification
notification. But do I need to have an EKEventStore
object "alive" for me to receive this notification? I'm thinking I'm initializing the EKEventStore
object in on view controller to retrieve some events. And then I will pop this view controller of the navigation stack and the view controller will be deallocated thus the EKEventStore
object will be deallocated.
Asked
Active
Viewed 2,211 times
2

Peter Warbo
- 11,136
- 14
- 98
- 193
-
[@Peter Warbo](http://stackoverflow.com/users/294661/peter-warbo) is your doubt cleared..? – Vimal Venugopalan Sep 08 '12 at 03:51
2 Answers
2
No, you don't need to keep the EKEventStore object alive as you are already registering EKEventStoreChangedNotification using EKEventStore object named eventStore
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(storeChanged:)
name:EKEventStoreChangedNotification object:eventStore];
Refer this for more clearance of your doubt

Vimal Venugopalan
- 4,091
- 3
- 16
- 25
0
For swift 3.x, use like below
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.storeChanged(_:)), name: NSNotification.Name.EKEventStoreChanged, object: eventStore)
...
...
...
//Method
func storeChanged(_ nsNotification: NSNotification) {
//do your stuff
}