Condividi tramite


NSManagedObjectContext.Notifications.ObserveObjectsDidChange Metodo

Definizione

Overload

ObserveObjectsDidChange(EventHandler<NSManagedObjectChangeEventArgs>)

Notifica fortemente tipizzata per la ObjectsDidChangeNotification costante.

ObserveObjectsDidChange(NSObject, EventHandler<NSManagedObjectChangeEventArgs>)

Notifica fortemente tipizzata per la ObjectsDidChangeNotification costante.

ObserveObjectsDidChange(EventHandler<NSManagedObjectChangeEventArgs>)

Notifica fortemente tipizzata per la ObjectsDidChangeNotification costante.

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

Parametri

handler
EventHandler<NSManagedObjectChangeEventArgs>

Metodo da richiamare quando viene pubblicata la notifica.

Restituisce

Oggetto token che può essere usato per arrestare la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

Nell'esempio seguente viene illustrato come gli sviluppatori possono usare questo metodo nel codice:

//
// Lambda style
//

// listening
notification = NSManagedObjectContext.Notifications.ObserveObjectsDidChange ((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.ObserveObjectsDidChange (Callback);
}

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

Si applica a

ObserveObjectsDidChange(NSObject, EventHandler<NSManagedObjectChangeEventArgs>)

Notifica fortemente tipizzata per la ObjectsDidChangeNotification costante.

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

Parametri

objectToObserve
NSObject

Oggetto da osservare.

handler
EventHandler<NSManagedObjectChangeEventArgs>

Metodo da richiamare quando viene pubblicata la notifica.

Restituisce

Oggetto token che può essere usato per arrestare la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

Questo metodo può essere usato per sottoscrivere ObjectsDidChangeNotification le notifiche.

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

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

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

Si applica a