我们可以替换应用程序委托旧的核心数据方法代替新的核心数据xcode 8.3方法吗?



我创建了一个使用 Xcode 8.3.2 和核心数据的新项目,这些核心数据方法的核心数据方法与使用 xcode 7 创建的核心数据方法不同。

它在iOS 10上运行,但尝试在iOS 9上运行时会出现错误。

新的核心数据方法,如

 @synthesize persistentContainer = _persistentContainer;
- (NSPersistentContainer *)persistentContainer {
    // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
    @synchronized (self) {
        if (_persistentContainer == nil) {
            _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"ieMalayalam"];
            [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
                if (error != nil) {
                    // 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();
                }
            }];
        }
    }
    return _persistentContainer;
}
- (void)saveContext {
    NSManagedObjectContext *context = self.managedObjectContext;
    NSError *error = nil;
    if ([context hasChanges] && ![context 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();
    }
}

我们能否取代旧的核心数据方法来支持ios 9和10?????请帮忙

这些方法更像是一个模板,为您提供有关如何实现核心数据的示例。创建包含核心数据的项目后,您的第一项工作是重构整个系统。一开始,您应该将整个逻辑远离应用程序委托。

因此,一旦你有一个很好的系统来处理核心数据,你可以将同一个系统复制到另一个项目中,随着时间的推移,你的系统可能会得到极大的改进和扩展,甚至可能准备好开源它。

如果您不能完成所有这些维护,您可以搜索一些开源。例如,我相信有相当多的古柯荚。我相信神奇记录被大量使用。

我通过将旧的核心数据方法(xcode 7(替换为新的(xcode 8(来修复它。

该应用程序在ios 9和10上运行。感谢您的所有愿景。

最新更新