同时使用 CoreData、多线程和绑定

发布于 2024-12-03 11:51:15 字数 673 浏览 2 评论 0原文

我创建了一个小型测试应用程序。它创建了一家新公司和 x 名员工。

员工是在自己的线程中创建的,一旦完成,他们就会被添加到公司中。

因为不允许在线程之间共享托管对象,所以我使用公司的对象 id。

为了不同时读/写相同的托管对象上下文,我为每个线程创建一个临时上下文。我使用 - (void)mergeChanges:(NSNotification *)Notifikation 并合并 man 上下文和线程上下文之间的更改。

我使用两个应用程序控制器和绑定在两个表视图中显示公司及其员工。

但仍然有一个错误我无法修复。每次我创建一个包含员工的新公司时,并非所有员工都出现在表视图中。不知怎的,他们迷路了,但我不知道在哪里。

我已在这里上传 Xcode 项目:http://uploading.com/files/7894m9mc/CoreDataMultiThreading。 zip/

我现在正在尝试寻找该错误一周:(也许其他人有更多的运气。

注意:我想用该应用程序尝试的是创建许多对象在自己的线程(员工)中,并在创建后立即将这些对象添加到同一个对象(公司)

(请原谅我的发音不好)

I have created a small test app. It creates a new company and a number of x employees.

The employees are created in their own thread and as soon as that's done, they will be added to a company.

Because it's not allowed to share managed objects between threads, I use the company's object id.

In order not to read/write the same managed object context at the same time, I create a temporary context for each thread. I use - (void)mergeChanges:(NSNotification *)Notifikation and merge the changes between the man context and the context from the thread.

I display both the company and its employees in two table views using two app controllers and bindings.

But there is still a bug I can't fix. Everytime I create a new company with employees, not all employees appear in the table view. Somehow they get lost, but I can't figure out where.

I have uploaded the Xcode project here: http://uploading.com/files/7894m9mc/CoreDataMultiThreading.zip/

I am trying to find the bug for one week now :( Maybe someone else has more luck.

Note: What I want to try with that app is to create many objects in their own thread (employees) and add these objects to one and the same object (company) as soon as they are created.

( please excuse my bad pronunciation )

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

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

发布评论

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

评论(1

抚笙 2024-12-10 11:51:15

出现此问题的原因是许多 Employee 对象在与前台线程合并后将其company 关系设置为 nil。由于它们没有 company 关系对象,因此它们不会显示在 UI 中。

我不确定为什么合并将关系设置为零。它可能与同时发生多个合并或尝试合并无故障的故障对象有关。

The problem is arising because many of the Employee objects have their company relationship set to nil after the merge with the foreground thread. Since they have no company relationship object, they don't show up in the UI.

I'm not sure why the merge is setting the relationship to nil. It might have something to do with having multiple merges occurring at the same time or with trying to merge unfaulted fault objects.

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