Realm: How to Add Two Results <(Object)> in Realm

For arrays, we could just do

resultArray = array1 + array2

      

I have two results from the <(Object)> results, how can I add them?

Do I need to quote or is there any other way?

+3


source share


2 answers


Results

does not support concatenation, but you can create GeneratorOf

one that will give the sum of the two results, or create [Object]

one that is a nonsense equivalent by doing



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

      

+2


source


RLMResults

are like an array, but not an array, so you cannot add them directly, you need to use predicates to get your results. This is mentioned in the Realm Doc

RLMResults is a type of automatic container update in Realm returned from object requests.

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 RLMArray

or RLMResults

to an existing one RLMArray

, you can use the – addObjects:

method RLMArray

only the condition is that both results must be of the same class. RLMArray Doc for reference.

+3


source







All Articles