gpt4 book ai didi

ios - 使用谓词获取核心数据中 parent 的所有 child

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:31:03 25 4
gpt4 key购买 nike

我在 Core Data 中有一个 Person - Children 的数据模型关系。例如,一个人可以有 child ,他的 child 可以有 child ,他的 child 的 child 也可以有 child 等等。

我如何才能使用谓词获取所有子项、孙子项和孙子项?

最佳答案

如果您有一个 Person 对象,thePerson,那么要获取他们的 child ,您可以使用以下谓词:

NSPredicate(format:"parent == %@", thePerson)

要获取他们的孙子,请使用:

NSPredicate(format:"parent.parent == %@", thePerson)

对于他们的曾孙,使用:

NSPredicate(format:"parent.parent.parent == %@", thePerson)

将它们组合在一起:

NSPredicate(format:"parent == %@ OR parent.parent == %@ OR parent.parent.parent == %@", thePerson, thePerson, thePerson)

关于ios - 使用谓词获取核心数据中 parent 的所有 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45933771/

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