简体   繁体   English

领域:如何在Realm中添加两个结果<(Object)>

[英]Realm: How to add two Results<(Object)> in Realm

For arrays we could just do 对于我们可以做的阵列

resultArray = array1 + array2

I have two results of Results<(Object)> how do I add them? 我有两个结果<(对象)>>如何添加它们?

Do I have to loop or is there in any other way? 我是否必须循环或以其他方式存在?

RLMResults are like array but not array, so you cannot add them directly, you have to use predicates to get your results. RLMResults就像数组但不是数组,所以你不能直接添加它们,你必须使用谓词来获得结果。 This is mentioned in Realm Doc Realm Doc中提到了这一点

RLMResults is an auto-updating container type in Realm returned from object queries. RLMResults是从对象查询返回的Realm中的自动更新容器类型。

RLMResults can be queried with the same predicates as RLMObject and RLMArray and you can chain queries to further filter query results. 可以使用与RLMObject和RLMArray相同的谓词查询RLMResults,并且可以链接查询以进一步过滤查询结果。

RLMResults cannot be created directly. 无法直接创建RLMResults。

But If you want to add objects of RLMArray or RLMResults in an existing RLMArray you can use – addObjects: method of RLMArray only condition is that both the results should be of the same class. 但是如果你想添加的对象RLMArrayRLMResults在现有RLMArray你可以使用– addObjects:RLMArray唯一的条件是,无论结果应该是同一类的。 RLMArray Doc for reference. RLMArray Doc供参考。

Results不支持连接,但是你可以创建一个GeneratorOf ,它将产生两个结果的总和,或者创建一个[Object] ,它是非懒惰的等价物

let sum = map(array1) { $0 } + map(array2) { $0}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM