要求Coredata是否一切都很好地同步?迅速

发布于 2025-02-10 14:48:37 字数 919 浏览 0 评论 0原文

我需要您在我的实体重复一会儿遇到的问题上的帮助。

让我解释一下,我有两个有关系的实体(项目和项目)。 在启动它的应用程序中,我会自动设置该项目数据,以创建我称为“收件箱”的项目数据,以便以后可以添加一个项目数据,而无需先创建列表。

问题在于,如果我删除我的应用程序并自动重新安装它,则将在已经存在时“收件箱”创建项目。 (我的假设仅仅是我的命令比启动Coredata更快的是所有数据)。

所以我的问题是。如何问Coredata是否一切都很好地同步,能够问他是否可以自动创建一个项目(收件箱)。

(这是我自动订单的摘要)

@FetchRequest(entity: Projects.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Projects.title, ascending: true)], predicate: NSPredicate(format: "isDefault == true")) var proje: FetchedResults<Projects>

if proje.count == 0 {
            let newC = Projects(context: self.viewContext)
            newC.title = String("\(inbox)")
            newC.isDefault = true
            newC.color = "lightGray"
            newC.id = UUID()
            do {
                try self.viewContext.save()
            } catch {
                NSLog(error.localizedDescription)
            }
        }

I need your help on a problem that I have for a little while of duplication in my entities.

Let me explain I have two entities that are in relationship (Item and Projects).
In my application when I launch it, I set up that automatically a Projects data that I would call "Inbox" is created so that I can add an Item data afterwards without having to create a List first.

The problem is that if I delete my app and reinstall it automatically the Projects "Inbox" will create when one already exists.
(my assumption is simply that my command is faster than launching Coredata is all the data from it).

So my question is. How to ask Coredata if everything is well synchronized to be able to ask him if I can create a Projects automatically (Inbox).

(here is a summary of my automatic order)

@FetchRequest(entity: Projects.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Projects.title, ascending: true)], predicate: NSPredicate(format: "isDefault == true")) var proje: FetchedResults<Projects>

if proje.count == 0 {
            let newC = Projects(context: self.viewContext)
            newC.title = String("\(inbox)")
            newC.isDefault = true
            newC.color = "lightGray"
            newC.id = UUID()
            do {
                try self.viewContext.save()
            } catch {
                NSLog(error.localizedDescription)
            }
        }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文