gpt4 book ai didi

ios - 针对特定集合的多对多关系核心数据查询

转载 作者:可可西里 更新时间:2023-11-01 02:00:14 25 4
gpt4 key购买 nike

enter image description here

public enum Ability: String {
case newcomer = "Newcomer"
case beginner = "Beginner"
case intermediate = "Intermediate"
case advanced = "Advanced"
}

public enum Group: String {
case solo = "Solo"
case duo = "Duo"
case team = "Team"
}

我想找到符合以下条件的所有性能。

ability == "Beginner"
group == "Duo"
performers == "Jane Davies" && "Alice Evans"

The documentation表明不支持核心数据中的聚合操作,这令人惊讶。此类问题已asked before在这里并建议使用“任何”。

据我了解,“Any”会返回包含“Jane”或“Alice”或“Jane & Alice”的表演,对吗?我只想要包含“Jane & Alice”的表演。

如何为这个查询编写谓词?

谢谢

最佳答案

对于(不同的)Performer 对象的列表,以下谓词应该有效找到与这些对象完全相关的所有 Performance 对象表演者:

let perf1 = ... // Performer object for "Jane Davies"
let perf2 = ... // Performer object for "Alice Evans"
let list = [perf1, perf2]

let predicate = NSPredicate(format: "performers.@count = %ld AND ALL performers in %@", list.count, list)

但显然不是。解决方法是使用子查询:

let predicate = NSPredicate(format: "performers.@count = %ld AND SUBQUERY(performers, $p, $p in %@).@count = %ld",
list.count, list, list.count)

关于ios - 针对特定集合的多对多关系核心数据查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47000763/

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