删除 OS X 上的 CoreData 存储?

发布于 2024-11-06 10:04:01 字数 233 浏览 0 评论 0原文

我正在 Mac OS X 应用程序中使用 CoreData。更改实体后,我收到以下错误:

用于打开持久存储的托管对象模型版本与用于创建持久存储的托管对象模型版本不兼容。

我为此问题找到的所有答案都建议在应用程序中实施版本控制/迁移,但我对保存数据不感兴趣。难道没有一个不太复杂的解决方案吗?比如删除库存文件之类的?如果是,该文件位于哪里?

谢谢。

I'm playing around with CoreData in a Mac OS X application. After changing an entity i got the following error:

The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store.

All answers i've found for this issue suggest implementing versioning/migration into the app, but I'm not interested in saving my data. Isn't there a less complicated solution for that? Like deleting the stock file or something like that? And if yes, where is this file located?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

等待我真够勒 2024-11-13 10:04:01

如果您不想要这些数据,那么可以,您只需删除旧文件并创建一个新文件即可。如果您的数据基于文档,则应删除文档本身。如果您对整个应用程序使用单个商店(不是基于文档),那么您应该查看创建商店对象的代码以查找位置。该模板将创建代码放置在应用程序委托中,存储的默认位置位于 ${HOME}/Library/Application Support/${APP_NAME}/ 中。

If you don't want the data, then yes, you can simply delete the old file and create a new one. If your data is document based, then the document itself should be deleted. If you use a single store for the whole application (not document based), then you should look in the code that creates the store object to find the location. The template places the creation code in the application delegate, and the default location for the store is in ${HOME}/Library/Application Support/${APP_NAME}/.

酸甜透明夹心 2024-11-13 10:04:01

在 OS X 10.7 Lion 上,当应用程序被沙盒化时,它存储在:

~/Library/Containers/com.yourcompany.yourAppName/

On OS X 10.7 Lion when the app is sandboxed, it is stored in:

~/Library/Containers/com.yourcompany.yourAppName/
記柔刀 2024-11-13 10:04:01

我发现对于 Mac OS X 10.8 / Xcode 4.6,数据存储在 下的派生数据文件夹中。

Users/*username*/Library/Developer/Xcode/DerivedData/*app name*-*random string*/Build/Products/Debug/*app name*.sqlite

删除此数据的最简单方法是转到组织器,选择项目选项卡,然后单击派生的“删除...”按钮数据。

I found that for Mac OS X 10.8 / Xcode 4.6 the data is stored in the derived data folder of under

Users/*username*/Library/Developer/Xcode/DerivedData/*app name*-*random string*/Build/Products/Debug/*app name*.sqlite

The easiest way to delete this data is to go to the organiser, select project tab and click "Delete..." button by derived data.

在梵高的星空下 2024-11-13 10:04:01

或者,对于 OSX,使用 Nsfilemanager 通过使用 lazy var permanentStoreCoordinator: NSPersistentStoreCoordinator{...} 中定义的 url 来删除文件。

在此 var permanentStoreCoordinator 中,将定义一个 url,该 url 被设计为由 persistenceStoreCoordinator 使用。您只需使用那里定义的 url 即可删除旧商店。插入以下代码。运行项目,文件将被删除。 然后删除代码以允许对象再次存储,而不是每次都删除数据。

这是我在 lazy var permanentStoreCoordinator: NSPercientStoreCoordinator 中找到的内容,

let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("CocoaAppCD.storedata")

这是我直接放在它下面的内容。

do{
    try NSFileManager.defaultManager().removeItemAtURL(url)
} catch{
    print("could not delete file")
}

然后我点击运行。它运行一次然后我删除我刚刚编写的代码,这样数据就不会每次都被删除

Alternatively, For OSX, use the Nsfilemanager to delete the file by using the url defined in the lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator{...}

In this var persistentStoreCoordinator a url will be defined that is designed to be used by the persistentStoreCoordinator. You can just use the url defined there to delete the old store. Insert the below code. Run the project and the file will be deleted. Then delete the code to allow objects to be stored again and not delete the data every time.

here is what I found in the lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator

let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("CocoaAppCD.storedata")

here is what i put immediately underneath it.

do{
    try NSFileManager.defaultManager().removeItemAtURL(url)
} catch{
    print("could not delete file")
}

then i clicked run. It ran once then i delete the code i just made so that the data would not be deleted every time

荒人说梦 2024-11-13 10:04:01

在 macOS Big Sur (11.4) 中,可以在以下位置找到本地 NSPersistentCloudKitContainer 核心数据存储:

~/Library/Containers/yourAppName/Data/CloudKit/

In macOS Big Sur (11.4), local NSPersistentCloudKitContainer Core Data storage can be found at:

~/Library/Containers/yourAppName/Data/CloudKit/

落日海湾 2024-11-13 10:04:01

在 Mac OS X 10.11.4 上,使用 Xcode 7.3 清理解决了我的问题:

Product > CleanShiftK

On Mac OS X 10.11.4 with Xcode 7.3 cleaning the fixed the problem for me:

Product > Clean or ShiftK

芯好空 2024-11-13 10:04:01

尝试在您以前未使用过的其他设备的模拟器中运行该应用,看看它是否对您有帮助(即 iPhone SE 而不是 iPhone 7)。如果是这样,那么删除损坏的文件夹应该会有所帮助。 打开终端并运行以下命令:

sudo rm -rf ~/Library/Developer/CoreSimulator/Devices

删除可能损坏的模拟器数据、

sudo rm -rf ~/Library/Developer/XCode/DerivedData/

删除应用程序的数据。

希望有帮助!

Try to run the app in a simulator of another device that you haven't used before and see if it helps you (i.e. iPhone SE instead of iPhone 7). If it does, then removing the corrupted folders should help. Open Terminal and run the following commands:

sudo rm -rf ~/Library/Developer/CoreSimulator/Devices

to remove the simulators' data that might be corrupted,

sudo rm -rf ~/Library/Developer/XCode/DerivedData/

to remove your app's data.

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文