gpt4 book ai didi

ios - 核心数据不会在两次发布之间持续存在

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:58 25 4
gpt4 key购买 nike

我在使用 Core Data 时遇到了一个奇怪的问题。在一个特定的 View Controller 中,我从 Core Data 中的对象加载 View 。当我运行该应用程序时,它第一次加载此 View 时,Core Data 不会从我的提取中返回任何内容。所以我重新填充核心数据,每次显示 View 时,它都会正确地从核心数据中获取对象。但是,每次启动该应用程序时,它都不会在 Core Data 中找到任何内容,然后必须再次从头开始创建对象。

那么什么会导致 Core Data 对象在应用程序运行期间持续存在,而不是在启动之间持续存在?我没有做任何事情来删除任何对象。

编辑:有什么方法可以查看 Core Data 中的实际内容吗?比如文件或我可以查看的东西?这将使它更容易调试。

最佳答案

确保在更改后保存上下文。模板方法是:

- (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.
NKLOG(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}

如果你想打开你的数据库,你可以尝试这个名为 SQLite Manager 的 firefox 插件

然后搜索您的 .sqlite 文件,您的应用程序的默认路径为:

/Users/YOUR_USER/Library/Application Support/iPhone Simulator/IOS_VERSION/Applications/GENERATED_HASH/Documents/YOUR_APP.sqlite

关于ios - 核心数据不会在两次发布之间持续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16720022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com