iOS Realm.io限制或采取功能

时间:2014-10-20 03:53:16

标签: ios objective-c realm

我似乎无法在文档中找到信息

我的应用中有一些简单的聊天功能。

@interface ZPChatMessageStoredModel : RLMObject

@property NSString *content;
@property NSString *contentType;
@property NSDate *createdOn;
@property NSString *senderUserId;
@property NSString *recipientUserId;

@end

我可以使用像这样的NSPredicate来查询模型:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"(senderUserId == %@ AND recipientUserId == %@) OR (senderUserId == %@ AND recipientUserId == %@)",senderUserId, recipientUserId, recipientUserId, senderUserId];

如何限制或取消查询?我只喜欢createdOn属性中最后30个降序排序。

1 个答案:

答案 0 :(得分:6)

使用Realm,您通常不需要出于性能原因限制结果,因为结果永远不会被复制,因此对查询时间的影响可以忽略不计。

如果是出于UI的原因,我们正在努力为我们的查询结果添加切片方法(根据这个帖子:https://groups.google.com/forum/#!topic/realm-cocoa/VcMfk2G8iaU)。同时,您应该将您感兴趣的结果复制到一个单独的数组中。