NSPersistentStoreCoordinator.StoresWillChangeNotification Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Константы уведомлений для 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
Значение свойства
Константа NSString должна использоваться в качестве маркера для NSNotificationCenter.
- Атрибуты
Комментарии
Эту константу можно использовать с для NSNotificationCenter регистрации прослушивателя для этого уведомления. Это NSString вместо строки, так как эти значения могут использоваться в качестве маркеров в некоторых собственных библиотеках, а не только для их фактического содержимого строки. Параметр notification для обратного вызова содержит дополнительные сведения, относящиеся к типу уведомления.
Чтобы подписаться на это уведомление, разработчики могут использовать удобный NSPersistentStoreCoordinator.Notificationsметод .ObserveStoresWillChange , который предоставляет строго типизированный доступ к параметрам уведомления.
В следующем примере показано, как использовать строго типизированный класс Notifications, чтобы вывести догадки из доступных свойств в уведомлении:
//
// 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 ();
}
В следующем примере показано, как использовать уведомление с 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);
}