gpt4 book ai didi

iOS CoreData 关系 : Use optional with or without minimum

转载 作者:可可西里 更新时间:2023-11-01 05:41:46 25 4
gpt4 key购买 nike

在核心数据中,您可以将关系设置为可选,但您可以将其设置为选中或不选中最小值...检查下面的图像以了解差异。我认为 我注意到的是,当您使用如下谓词搜索对象时:@"object != %@", objectToSearchFor,第一个设置返回 nil但第二个设置没有。我可能会弄错,但有人知道这两种设置之间的区别吗?

Optional relationship without minimum

Optional relationship with minimum

附言我不知道这是否重要,但我使用 SQLite 作为数据库引擎。

最佳答案

NSRelationshipDescription Class Reference 中有一些关于此的文档:

Cardinality
The maximum and minimum counts for a relationship indicate the number of objects referenced (1 for a to-one relationship, -1 means undefined). The counts are only enforced if the relationship value in the containing object is not nil. That is, provided that the relationship value is optional, there may be zero objects in the relationship, which might be less than the minimum count.

例如,在可选的一对多关系的情况下:关系的值必须是 nil,或者至少包含所需对象的最小数量。

在可选的一对一关系的情况下,关系值要么是 nil 要么指向另一个对象,所以我想不出最小计数是否有区别的情况0 或 1。

在保存托管对象上下文时会检查所有约束,例如最小和最大计数等。

关于iOS CoreData 关系 : Use optional with or without minimum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14273858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com