要求Coredata是否一切都很好地同步?迅速
我需要您在我的实体重复一会儿遇到的问题上的帮助。
让我解释一下,我有两个有关系的实体(项目和项目)。 在启动它的应用程序中,我会自动设置该项目数据,以创建我称为“收件箱”的项目数据,以便以后可以添加一个项目数据,而无需先创建列表。
问题在于,如果我删除我的应用程序并自动重新安装它,则将在已经存在时“收件箱”创建项目。 (我的假设仅仅是我的命令比启动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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论