ios - 将 RLMResults 转换为 RLMArray

标签 ios swift realm

我正在使用 objectsWhere 查询 RLMArray,我得到了一个 RLMResults,但我需要一个 RLMArray,其结果在我的代码中。

private var data: RLMArray?

self.data = self.currentSubcategory!.datasheets // is a RLMArray
self.data = self.data!.objectsWhere("is_favourite = 1")

最佳答案

RLMArray has been split into two classes: RLMArray and RLMResults. RLMArray is now used only for to-many properties on RLMObject classes, while RLMResults is used for all of the querying and sorting methods. This was done to reflect that the two actually had fairly different APIs (for example, RLMResults does not have addObject:), and they’re expected to diverge further as we add change notifications for queries.

The migration for this should be as simple as replacing RLMArray with RLMResults in all of the places that the compiler complains about.

To go with this, arraySortedByProperty:ascending: has been renamed to sortedResultsUsingProperty:ascending:, and addObjectsFromArray: has been renamed to addObjects: to reflect the fact that you can pass any enumerable object to it (such as NSArray, RLMArray, or RLMResults).

来源:http://realm.io/news/realm-cocoa-0.87.0/#rlmresults

希望这就足够了

关于ios - 将 RLMResults 转换为 RLMArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27129566/

相关文章:

iOS 在 MFMailComposeViewController 和 SKStoreProductViewController 的 init 方法上崩溃

swift - SpriteKit 位置如何运作?

ios - UICollectionView 单元格选择的奇怪行为

swift - swift toInt() 中的用户输入返回 nil

ios - 调用 Realm().objects 时使用未实现的初始化程序 'init(realm:schema:)'

ios - 上次单击时如何使按钮 UIButton 保存

ios - Multipeer Connectivity 数据仅以一种方式发送,即使两个设备都已连接

ios - self.view.frame.size.height 1004 而不是 1024

java - 将图像存储在 Realm 数据库中

ios - 未在 NSURLSession 上调用 API