gpt4 book ai didi

iphone - 将字符串属性添加到 CoreDataBooks

转载 作者:行者123 更新时间:2023-11-28 23:17:49 25 4
gpt4 key购买 nike

我一直在摆弄 CoreDataBooks,并试图在当前的三个字段之外向 sqlite 文件添加另一个字段。我在 .xcdatamodel 中添加了属性字符串,并在 book.h、book.m 和本地化文件中声明了它(所有这些都没有更改 sqlite 文件)。但是,这些更改永远不会在 sqlite 中添加字段,并且应用程序永远不会加载。每次我在模拟器中删除应用程序并执行构建--> 清理,但无济于事。我也尝试更改 sqlite 文件以匹配 .xcdatamodel,但应用程序仍然无法加载。

这是 CoreDataBooks 的问题还是我的问题?在执行此操作之前我需要对应用程序进行版本控制吗?只要我在模拟器中删除应用程序,我似乎就不必这样做。

有人知道如何在 CoreDataBooks 中添加第四个字符串属性(sqlite 字段)吗?

提前致谢!

最佳答案

我在 CoreDataBooks 中找到了这么好的一段代码

NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"CoreDataBooks.sqlite"];
/*
Set up the store.
For the sake of illustration, provide a pre-populated default store.
*/
NSFileManager *fileManager = [NSFileManager defaultManager];
// If the expected store doesn't exist, copy the default store.
if (![fileManager fileExistsAtPath:storePath]) {
NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"CoreDataBooks" ofType:@"sqlite"];
if (defaultStorePath) {
[fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
}
}

CoreDataBooksAppDelegate.m:154 中,这对我来说意味着每次应用程序找不到 sqlite 文件时,它都是从未通过修改 CoreDataBooks.xcdatamodel< 更改的包中复制的/strong>.

尝试使用其他方法,或者只修改捆绑的 sqlite 文件。

关于iphone - 将字符串属性添加到 CoreDataBooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196365/

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