简体   繁体   中英

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. This is mentioned in Realm Doc

RLMResults is an auto-updating container type in Realm returned from object queries.

RLMResults can be queried with the same predicates as RLMObject and RLMArray and you can chain queries to further filter query results.

RLMResults cannot be created directly.

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. RLMArray Doc for reference.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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