Ios 在NSManagedObjectContext上调用saveContext过多

Ios 在NSManagedObjectContext上调用saveContext过多,ios,core-data,Ios,Core Data,我想知道您是否可以经常调用NSManagedObjectContext save。我的保存代码是标准UIApplicationLegate代码: - (void)saveContext { NSError *error = nil; NSManagedObjectContext *managedObjectContext = self.managedObjectContext; if (managedObjectContext != nil) { if (

我想知道您是否可以经常调用NSManagedObjectContext save。我的保存代码是标准UIApplicationLegate代码:

- (void)saveContext
{
    NSError *error = nil;
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil) {
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
            // Replace this implementation with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
    }
}

我有一个应用程序,可以打开一个模式来创建一个新的报警类型对象。模态有几个屏幕,就像重复的几天一样。与苹果的重复天数视图类似,我推出了一个新的viewController,它只显示重复的天数。当我返回到模式的主屏幕,用户在其中输入报警名称时,我可以调用saveContext吗?我想我想知道我是否需要担心为较小的屏幕调用saveContext,比如重复几天,然后用户点击主模式屏幕上的“完成”,我立即再次调用saveContext

如果整个应用程序中只有一个
NSManagedObjectContext
,则无需频繁调用
-save
(只要应用程序不崩溃!)。在这种情况下,如果某些信息已更改,我通常在离开编辑屏幕时保存,并将其保存在应用程序代理中
-applicationidenterbackground:

如果您有很多更改(新对象、更新等),那么调用save可能会有点昂贵,因为它必须将这些更改写入持久化存储(磁盘上的文件-假设您使用的是
NSPersistedStore