问题标签 [nsmanagedobjectmodel]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
7 回答
13825 浏览

ios - 如何在框架内使用 Core Data 的 ManagedObjectModel?

我正在尝试将我的一个应用程序的特定部分迁移到一个框架中,以便我可以在我的应用程序本身和那些花哨的新 iOS 8 小部件之一中使用它。这部分是处理我在 Core Data 中的所有数据的部分。将所有内容移动并访问它非常简单。我只是无法访问momd那里的文件。

创建时,NSManagedObjectModel我仍然尝试加载momdApple 的代码模板中所示的内容:

不幸的是,在访问modelURLCore Data 堆栈时会出现以下错误nil并因此崩溃:MyApp

那么,在使用 Core Data 的框架内工作时,正确的方法是什么?

0 投票
1 回答
103 浏览

core-data - 运行时为 NSPersistentDocument 生成的自定义 NSManagedObjectModel

我有一个使用 Core Data 的基于文档的 (OS X) 应用程序,因此该文档是 NSPersistentDocument 的子类。当用户创建一个文档时,他/她指定一个设置来确定受管对象模型中特定实体具有的属性数量。例如,“棒球比赛”实体可以有 4 到 9 局属性,这取决于用户在创建文档时指定的数量。出于效率目的,托管对象模型是在文档创建时生成的,其中棒球比赛实体恰好包含指定的局数属性。因此,五局文档将具有与九局文档不同的管理对象模型。

要动态设置托管对象模型,我必须-(id)managedObjectModel在文档中覆盖。这是微不足道的,我可以轻松地提供具有适当数量的局数的托管对象模型。但是,如果用户打开一个保存的文档(局数未知),我再次被要求通过它为文档提供其托管对象模型-(id)managedObjectModel. 我的难题是,如果我不认识自己,我怎么能告诉文件它有多少局?托管对象模型是在运行时创建和设置的,因此明智的做法是在文档中添加某种属性,告诉我有多少局。我正在考虑基于每个文档类似于 NSUserDefaults 的东西,但不存在这样的东西。我能想到的唯一方法是存储任何明确给我局数的实体/属性,但在我给文档提供其托管对象模型之前,它是不可访问的!解决这个问题的正确方法是什么?

0 投票
1 回答
1289 浏览

objective-c - swift_dynamicCastClassUnconditional 问题

我有以下NSManagedObject迅速:

我有一个类,它提供具有以下功能的值:

当我从一个类中调用这个函数时Objective-C,一切正常。我这样称呼:

我可以从那里继续。当我从这样的Swift类中调用它时:

我得到了swift_dynamicCastClassUnconditional每一次。有什么我做错了吗?为什么相同的功能起作用Objective-C而不起作用Swift?我什至放了一个断点,可以在Swift调用时确认返回是一个有效的变量!有些方法Swift只是缺少它。

我尝试阅读以下内容:

http://jamesonquave.com/blog/understanding-the-fatal-error-cant-unwrap-optional-none-errors-in-swift/

在 XCTestCase 中的 Swift XCode 6 Beta 4 中进行转换时,NSFetchRequest 返回的 AnyObject 数组出现“Swift 动态转换失败”错误

还有什么我想念的吗?

0 投票
1 回答
1268 浏览

objective-c - '+entityForName: nil 不是用于搜索实体名称的合法 NSPersistentStoreCoordinator

稍后在使用 _managedObjectModel 时在程序中获取异常。下面是初始化代码。

问题是 _managedObjectModel 指向一个垃圾内存位置。在分析 GPR 和汇编代码后,我发现 ManagedObjectModel 已正确初始化,但是,当模式中的内容被加载到其中时 - 对象指针开始指向随机位置,远在对象之前,或者在对象分配的内存之间的某个位置.

如果我尝试使用以下内容访问底层内容:[_managedObjectModel->_entities allKeys],我确实获得了模式中的所有键。

有没有人遇到过这样的问题?

这可能类似于https://github.com/typhoon-framework/Typhoon/issues/138

0 投票
0 回答
75 浏览

ios - 核心数据 - 迁移到新模型名称

我现在正在更新商店中有一个应用程序。我做了很多核心数据更改,包括更改“lazy var managedObjectModel: NSManagedObjectModel”和“lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator?”中的名称。

如何正确使用 Core Data Migration 来确保现有用户下载更新时,应用不会在他们身上崩溃?

0 投票
1 回答
57 浏览

ios - A way to persist a duplicate version of the core data model temporarily

This is a bit of a tough question to explain. I've been looking for an answer to this over two weeks but I couldn't find a solution for this use case.

Before I get into the nitty gritty details, please have a look at this image. enter image description here

The user is presented with the Main List view at first. The data (patient records) shown in this view is fetched from an API. One important thing to note here is that the data is retrieved only for the current date. There are records for the past days and days to come in the database but by default the data is of current date. After I call the API and get the data, I create objects out of them and store those objects in Core Data. Then I fetch them from my core data model and display them in the table view.

Each Patient record in Main List is actually a group of smaller records. When the user taps on a record, he is taken to a Sub List where you can see all those smaller record details. He can also edit, delete these smaller record items.

Here's where I need help. While the user is in the Sub List he can change the date from within that view. And it should display the small record details for the newly selected date. This means calling the API again, sending the selected date as a parameter and get the data for that date and display them in the Sub List view.

But this whole date changing operation has no effect on the Main List's data. In other words, the Main List's current date's data should not change even though the date was changed inside the Sub List. If/when the user taps the back button to get to the Main List, the old, current date's data should be readily available as he left it and the new data in the Sub List view is discarded upon leaving that view.

Another thing is although the new data is temporary, the user still needs to be able to edit those records. It's not simply for display purposes. That's why I need to add them to core data.

My question is once I get the data for the new date within the Sub List, is there a way I can persist that data temporarily without affecting my original data set?

I'd really appreciate any help.

Thank you.

0 投票
0 回答
51 浏览

ios - 核心数据“无法加载名为...的类”

我正在学习核心数据,但我遇到了问题。我尝试了很多东西,但 xcode 总是告诉我:

2015-04-25 21:20:44.057 CoreData2 [8979:202376] CoreData:警告:无法为实体“联系人”加载名为“联系人”的类。找不到类,而是使用默认的 NSManagedObject。

这是我从 viewDidLoad 调用的方法:

我的 .xcdatamodeld

我的 Contacts.swift 文件:

有人知道我做错了什么吗?谢谢!

0 投票
1 回答
262 浏览

ios - 在另一个版本中更改 NSManagedObject 父实体

有没有什么好方法可以在另一个版本中更改 NSManagedObject 的父实体?
假设在模型版本 1.1 上我得到了:

  • anObject - 没有父实体

在 1.2 版中,我想让它继承自

  • object - 1.1 版中已经存在并包含属性“objectID”的父类

当我更改它的父实体时,应用程序崩溃:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法创建托管对象上下文:持久存储协调器没有任何持久存储。这可能意味着您忘记添加持久存储,或者您尝试这样做失败并出现错误。

这个答案中,建议在新版本中创建具有不同名称的新实体,并删除旧实体。
我的问题是这种问题是否有“更清洁”的解决方案?
如何将映射模型添加到项目/当前模型?

0 投票
2 回答
115 浏览

ios - “NSInternalInconsistencyException”配置的实体必须已经在模型中

我正在尝试在我的NSIncrementalStore Subclass的NSManagedObjectModel中添加一个新实体。我在 loadMetadata 方法中执行此操作,但它一直在最后一行抛出此异常。请参阅下面的代码

“NSInternalInconsistencyException”配置的实体必须已经在模型中

代码

0 投票
1 回答
25 浏览

ios - 在框架中包含 ManagedObjectModel

我正在开发一个框架,我想在其中包含一个NSManagedObjectModel抽象实体,这些实体被设计为在应用程序中进行子类化。应用程序是否可以NSManagedObjectModel在框架中子类化实体?