【问题标题】:Can We Replace App delegate old core data methods in place of new core data xcode 8.3 method我们可以替换 App 委托旧的核心数据方法来代替新的核心数据 xcode 8.3 方法吗
【发布时间】:2017-05-11 06:42:29
【问题描述】:

我使用 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 吗????? 请帮忙

【问题讨论】:

  • 不。你不能那样做。

标签: ios objective-c xcode core-data


【解决方案1】:

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

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

如果您无法完成所有维护工作,您可以搜索一些开源代码。例如,我相信有不少古柯豆荚。我相信Magical Record用得挺多的。

【讨论】:

    【解决方案2】:

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

    该应用程序同时在 ios 9 和 10 上运行。 感谢您的所有远见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      相关资源
      最近更新 更多