如何使RLMResults可变? [英] How to make RLMResults mutable?
问题描述
领域文档说RLMResults
舔NSArray
.我从数据库返回了一些结果,我想将其合并到另一个RLMResults
中.但是,这似乎是一成不变的,如何使RLMResults
从另一个RLMResults
添加对象?或使其可变?或将其转换为NSArray
?
The Realm doc says the RLMResults
are lick NSArray
. I have some results returned from the database and I want to merge it into another RLMResults
. But it seems it's immutable, How to make a RLMResults
add objects from another RLMResults
? or make it mutable? or convert it to NSArray
?
推荐答案
当前,这是您必须手动执行的操作.您可以通过串联两个结果来创建RLMArray.
Currently this is something you would have to do manually. You could create an RLMArray by concatenating your two results.
尽管如此,我们将在路线图的后面讨论同类型RLMObject的并集/合并方法.
We are discussing a union/merge method further down on the roadmap for RLMObjects of the same type though.
您可以分享的任何信息将帮助我们理解用例,并可能影响api设计
Any bit you can share will help us understand the use cases and potentially impact the api design
只要它们是同一类型,这是一个通用示例
As long as they are the same type, here's a generic example
let currentTask = Task.objectsWhere("name = %@", "First task").firstObject() as Task
let currentRecords = currentTask.records
let arrayOfRecords = RLMArray(objectClassName: "Record")
arrayOfRecords.addObjects(currentRecords)
let futureTask = Task.objectsWhere("name = %@", "Future task").firstObject() as Task
let futureRecords = futureTask.records
arrayOfRecords.addObjects(futureRecords)
这篇关于如何使RLMResults可变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!