Xcode一致性错误:设置无操作删除规则...是一个高级设置 [英] Xcode consistency error: Setting the No Action Delete Rule... is an advanced setting
问题描述
在Xcode中创建数据模型后,每个对象关系都会抛出以下错误:
After creating a data model in Xcode, it's throwing the following error for each of the object relationships:
Consistency Error:
Setting the No Action Delete Rule on [object relationship] is an advanced setting
什么是Xcode试图告诉我,我该如何回应?
What is Xcode trying to tell me, and how should I respond?
推荐答案
Core Data使用反向关系和删除规则来保持对象图一致
Core Data uses inverse relationships and delete rules to keep the object graph consistent
假设您有A.foo< 1— 1> B.bar和do a.foo = b
。这将自动(有效地)执行 b.bar = a
。
Let's say you have A.foo <1—1> B.bar and do a.foo = b
. This automatically (effectively) performs b.bar = a
.
您 [b delete]
。使用nullify规则,有效地 b.bar.foo = nil
。使用cascade,它会 [b.bar delete]
。用无动作,它什么也不做; a.foo
现在是一个棘手的核心数据对象引用。
Now let's say you [b delete]
. With the "nullify" rule, effectively does b.bar.foo = nil
. With "cascade", it does [b.bar delete]
. With "no action", it does nothing; a.foo
is now a "dangling Core Data object reference".
这不是一个悬挂指针;标准内存管理规则意味着 b
将仍然存在于内存中,而 a
指向它(直到 a
会变成错误),但 a.foo
将永远指向已删除的对象,当您尝试访问它属性。我不知道当您保存并重新获取
It's not really a dangling pointer; standard memory management rules mean that b
will still exist in memory while a
points to it (until a
turns into a fault), but a.foo
will forever refer to a deleted object, which raises an exception when you try to access its properties. I'm not sure what happens when you save and re-fetch a
either.
- 多关系,它变得更复杂。实现详细信息:此关系似乎是由一个实体拥有,并且仅在实体保存时才会保存(我尝试在不同MOC之间建立关系时遇到此错误:保存的MOC不拥有更新的实体,因此关系从未保存)。显然,当您同时删除 a
和 b
一个假定关系消失,只有一个被删除(但你不知道哪一个!)。
With a many-to-many relationship, it gets more complicated. Implementation details: The relationship appears to be "owned" by one of the entities, and is only saved when that entity is saved (I hit this bug when trying to set up a relationship across different MOCs: the MOC that saved didn't own the updated entity, so the relationship was never saved). Clearly when you delete both a
and b
, the relationships should also be removed, so one assumes that the relationship disappears only one of them is removed (but you don't know which one!).
你可能想要Nullify或Cascade。我从来不使用Cascade,因为我永远不会记得级联发生在哪个方向。
You probably want Nullify or Cascade. I never use Cascade because I can never remember which direction the cascading happens in.
这篇关于Xcode一致性错误:设置无操作删除规则...是一个高级设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!