Xcode 一致性错误:设置无操作删除规则...是高级设置
在 Xcode 中创建数据模型后,它会为每个对象关系抛出以下错误:
Consistency Error:
Setting the No Action Delete Rule on [object relationship] 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
What is Xcode trying to tell me, and how should I respond?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Core Data 使用逆关系和删除规则来保持对象图一致
假设您有 A.foo <1—1>; B.bar 并执行
a.foo = b
。这自动(有效地)执行b.bar = a
。现在假设您
[b删除]
。使用“nullify”规则,可以有效地执行b.bar.foo = nil
。对于“cascade”,它会执行[b.bar delete]
。 “无为”,就是什么都不做;“无为”,就是什么都不做。a.foo
现在是“悬空核心数据对象引用”。它实际上并不是一个悬空指针;而是一个悬空指针。标准内存管理规则意味着,当
a
指向它时,b
仍然存在于内存中(直到a
变成错误),但是>a.foo
将永远引用已删除的对象,当您尝试访问其属性时,这会引发异常。我也不确定当您保存并重新获取a
时会发生什么。对于多对多关系,情况会变得更加复杂。实现细节:该关系似乎由其中一个实体“拥有”,并且仅在保存该实体时才保存(当我尝试在不同的 MOC 之间建立关系时遇到此错误:保存的 MOC 不拥有更新的实体,因此关系从未保存)。显然,当您删除两者
a
和b
时,关系也应该被删除,因此人们假设关系消失,仅删除其中一个(但你不知道是哪一个!)。您可能需要 Nullify 或 Cascade。我从不使用级联,因为我永远不记得级联发生在哪个方向。
Core Data uses inverse relationships and delete rules to keep the object graph consistent
Let's say you have A.foo <1—1> B.bar and do
a.foo = b
. This automatically (effectively) performsb.bar = a
.Now let's say you
[b delete]
. With the "nullify" rule, effectively doesb.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".It's not really a dangling pointer; standard memory management rules mean that
b
will still exist in memory whilea
points to it (untila
turns into a fault), buta.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-fetcha
either.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
andb
, 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!).You probably want Nullify or Cascade. I never use Cascade because I can never remember which direction the cascading happens in.
拒绝
如果关系目标处至少有一个对象,则无法删除源对象。
例如,如果您要删除一个部门,则必须确保该部门的所有员工首先转移到其他地方(或解雇!),否则该部门无法删除。
无效
将目标处对象的逆关系设置为 null。
例如,删除一个部门,则将当前所有成员的部门设置为空。仅当员工的部门关系是可选的,或者确保在下一次保存操作之前为每个员工设置新部门时,这才有意义。
级联
删除关系目的地处的对象。
例如,如果您删除一个部门,请同时解雇该部门的所有员工。
无操作
对关系目的地处的对象不执行任何操作。
例如,如果您删除一个部门,请让所有员工保持原样,即使他们仍然认为自己属于该部门。
Deny
If there is at least one object at the relationship destination, then the source object cannot be deleted.
For example, if you want to remove a department, you must ensure that all the employees in that department are first transferred elsewhere (or fired!) otherwise the department cannot be deleted.
Nullify
Set the inverse relationship for objects at the destination to null.
For example, if you delete a department, set the department for all the current members to null. This only makes sense if the department relationship for an employee is optional, or if you ensure that you set a new department for each of the employees before the next save operation.
Cascade
Delete the objects at the destination of the relationship.
For example, if you delete a department, fire all the employees in that department at the same time.
No Action
Do nothing to the object at the destination of the relationship.
For example, if you delete a department, leave all the employees as they are, even if they still believe they belong to that department.