NSManagedObjectContext.Notifications.ObserveDidSave Method

Definition

Overloads

ObserveDidSave(EventHandler<NSManagedObjectChangeEventArgs>)

Strongly typed notification for the DidSaveNotification constant.

ObserveDidSave(NSObject, EventHandler<NSManagedObjectChangeEventArgs>)

Strongly typed notification for the DidSaveNotification constant.

ObserveDidSave(EventHandler<NSManagedObjectChangeEventArgs>)

Strongly typed notification for the DidSaveNotification constant.

public static Foundation.NSObject ObserveDidSave (EventHandler<CoreData.NSManagedObjectChangeEventArgs> handler);
static member ObserveDidSave : EventHandler<CoreData.NSManagedObjectChangeEventArgs> -> Foundation.NSObject

Parameters

handler
EventHandler<NSManagedObjectChangeEventArgs>

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 = NSManagedObjectContext.Notifications.ObserveDidSave ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("InsertedObjects", args.InsertedObjects);
    Console.WriteLine ("UpdatedObjects", args.UpdatedObjects);
    Console.WriteLine ("DeletedObjects", args.DeletedObjects);
    Console.WriteLine ("RefreshedObjects", args.RefreshedObjects);
    Console.WriteLine ("InvalidatedObjects", args.InvalidatedObjects);
    Console.WriteLine ("InvalidatedAllObjects", args.InvalidatedAllObjects);
});

// To stop listening:
notification.Dispose ();

//
//Method style
//
NSObject notification;
void Callback (object sender, CoreData.NSManagedObjectChangeEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("InsertedObjects", args.InsertedObjects);
    Console.WriteLine ("UpdatedObjects", args.UpdatedObjects);
    Console.WriteLine ("DeletedObjects", args.DeletedObjects);
    Console.WriteLine ("RefreshedObjects", args.RefreshedObjects);
    Console.WriteLine ("InvalidatedObjects", args.InvalidatedObjects);
    Console.WriteLine ("InvalidatedAllObjects", args.InvalidatedAllObjects);
}

void Setup ()
{
    notification = NSManagedObjectContext.Notifications.ObserveDidSave (Callback);
}

void Teardown ()
{
    notification.Dispose ();
}

Applies to

ObserveDidSave(NSObject, EventHandler<NSManagedObjectChangeEventArgs>)

Strongly typed notification for the DidSaveNotification constant.

public static Foundation.NSObject ObserveDidSave (Foundation.NSObject objectToObserve, EventHandler<CoreData.NSManagedObjectChangeEventArgs> handler);
static member ObserveDidSave : Foundation.NSObject * EventHandler<CoreData.NSManagedObjectChangeEventArgs> -> Foundation.NSObject

Parameters

objectToObserve
NSObject

The object to observe.

handler
EventHandler<NSManagedObjectChangeEventArgs>

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 DidSaveNotification notifications.

// Listen to all notifications posted for any object
var token = NSManagedObjectContext.Notifications.ObserveDidSave ((notification) => {
	Console.WriteLine ("Observed DidSaveNotification!");
};

// Listen to all notifications posted for a single object
var token = NSManagedObjectContext.Notifications.ObserveDidSave (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed DidSaveNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Applies to