NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
ObserveStoresWillChange(EventHandler<NSPersistentStoreCoordinatorStoreChangeEventArgs>) |
Strongly typed notification for the StoresWillChangeNotification constant. |
ObserveStoresWillChange(NSObject, EventHandler<NSPersistentStoreCoordinatorStoreChangeEventArgs>) |
Strongly typed notification for the StoresWillChangeNotification constant. |
ObserveStoresWillChange(EventHandler<NSPersistentStoreCoordinatorStoreChangeEventArgs>)
Strongly typed notification for the StoresWillChangeNotification constant.
public static Foundation.NSObject ObserveStoresWillChange (EventHandler<CoreData.NSPersistentStoreCoordinatorStoreChangeEventArgs> handler);
static member ObserveStoresWillChange : EventHandler<CoreData.NSPersistentStoreCoordinatorStoreChangeEventArgs> -> Foundation.NSObject
Parameters
Method to invoke when the notification is posted.
Returns
Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)
Remarks
The following example shows how developers can use this method in their code:
//
// Lambda style
//
// listening
notification = NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange ((sender, args) => {
/* Access strongly typed args */
Console.WriteLine ("Notification: {0}", args.Notification);
Console.WriteLine ("EventType", args.EventType);
});
// To stop listening:
notification.Dispose ();
//
//Method style
//
NSObject notification;
void Callback (object sender, CoreData.NSPersistentStoreCoordinatorStoreChangeEventArgs args)
{
// Access strongly typed args
Console.WriteLine ("Notification: {0}", args.Notification);
Console.WriteLine ("EventType", args.EventType);
}
void Setup ()
{
notification = NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange (Callback);
}
void Teardown ()
{
notification.Dispose ();
}
Applies to
ObserveStoresWillChange(NSObject, EventHandler<NSPersistentStoreCoordinatorStoreChangeEventArgs>)
Strongly typed notification for the StoresWillChangeNotification constant.
public static Foundation.NSObject ObserveStoresWillChange (Foundation.NSObject objectToObserve, EventHandler<CoreData.NSPersistentStoreCoordinatorStoreChangeEventArgs> handler);
static member ObserveStoresWillChange : Foundation.NSObject * EventHandler<CoreData.NSPersistentStoreCoordinatorStoreChangeEventArgs> -> Foundation.NSObject
Parameters
- objectToObserve
- NSObject
The object to observe.
Method to invoke when the notification is posted.
Returns
Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)
Remarks
This method can be used to subscribe for StoresWillChangeNotification notifications.
// Listen to all notifications posted for any object
var token = NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange ((notification) => {
Console.WriteLine ("Observed StoresWillChangeNotification!");
};
// Listen to all notifications posted for a single object
var token = NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange (objectToObserve, (notification) => {
Console.WriteLine ($"Observed StoresWillChangeNotification for {nameof (objectToObserve)}!");
};
// Stop listening for notifications
token.Dispose ();