Partager via


NSPersistentStoreCoordinator.StoresWillChangeNotification Propriété

Définition

Constante de notification pour StoresWillChange

[Foundation.Advice("Use NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange helper method instead.")]
[Foundation.Field("NSPersistentStoreCoordinatorStoresWillChangeNotification", "CoreData")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 9, ObjCRuntime.PlatformArchitecture.All, null)]
public static Foundation.NSString StoresWillChangeNotification { [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)] [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 9, ObjCRuntime.PlatformArchitecture.All, null)] get; }
member this.StoresWillChangeNotification : Foundation.NSString

Valeur de propriété

La constante NSString doit être utilisée comme jeton pour NSNotificationCenter.

Attributs

Remarques

Cette constante peut être utilisée avec pour NSNotificationCenter inscrire un écouteur pour cette notification. Il s’agit d’un NSString au lieu d’une chaîne, car ces valeurs peuvent être utilisées comme jetons dans certaines bibliothèques natives au lieu d’être utilisées uniquement pour leur contenu de chaîne réel. Le paramètre « notification » du rappel contient des informations supplémentaires spécifiques au type de notification.

Pour s’abonner à cette notification, les développeurs peuvent utiliser la méthode pratique NSPersistentStoreCoordinator.Notifications.ObserveStoresWillChange qui offre un accès fortement typé aux paramètres de la notification.

L’exemple suivant montre comment utiliser la classe Notifications fortement typée pour extraire les estimations des propriétés disponibles dans la notification :

//
// 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 ();
}

L’exemple suivant montre comment utiliser la notification avec l’API DefaultCenter :

// Lambda style
NSNotificationCenter.DefaultCenter.AddObserver (
        NSPersistentStoreCoordinator.StoresWillChangeNotification, (notification) => {Console.WriteLine ("Received the notification NSPersistentStoreCoordinator", notification); }


// Method style
void Callback (NSNotification notification)
{
    Console.WriteLine ("Received a notification NSPersistentStoreCoordinator", notification);
}

void Setup ()
{
    NSNotificationCenter.DefaultCenter.AddObserver (NSPersistentStoreCoordinator.StoresWillChangeNotification, Callback);
}

S’applique à