如何检查数组是否包含在集合中?
How to check if an array is contained in a collection?
假设我有
class A
{
dynamic var id = 0
dynamic var text = ""
}
class B
{
dynamic var id = 0
let collection = List<A>
}
我想知道 Int
(ids) 的数组是否包含在 B.collection
上(匹配 id
属性)。像这样
realm.objects(B).filter("%@ in collection.map{[=11=].id}", [1,2]) // pseudocode, obviously wrong
我很高兴能够检查 collection
是否包含单个 Int
(再次测试 id
属性)。我尝试使用 SUBQUERY
,但找不到正确的语法。
谢谢
realm.objects(B).filter("ANY collection.id IN %@", [1, 2])
将为您提供所有 B
个对象,其中 collection
有一个 A
对象 id
为 1 或 2。
假设我有
class A
{
dynamic var id = 0
dynamic var text = ""
}
class B
{
dynamic var id = 0
let collection = List<A>
}
我想知道 Int
(ids) 的数组是否包含在 B.collection
上(匹配 id
属性)。像这样
realm.objects(B).filter("%@ in collection.map{[=11=].id}", [1,2]) // pseudocode, obviously wrong
我很高兴能够检查 collection
是否包含单个 Int
(再次测试 id
属性)。我尝试使用 SUBQUERY
,但找不到正确的语法。
谢谢
realm.objects(B).filter("ANY collection.id IN %@", [1, 2])
将为您提供所有 B
个对象,其中 collection
有一个 A
对象 id
为 1 或 2。