Max Alexander
Max Alexander

Reputation: 5581

iOS Realm.io Limit or Take Functionality

I cannot seem to find the information in the documentation

I have some simple chat functionality in my app.

@interface ZPChatMessageStoredModel : RLMObject

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

@end

I can query the model with an NSPredicate like so:

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

How do I limit or take from the query? I'd only like the last 30 sorted descending on the createdOn property.

Upvotes: 1

Views: 1471

Answers (1)

timanglade
timanglade

Reputation: 371

with Realm you usually don’t need to limit results for performance reasons, as the results are never copied, so the impact on query times is negligible.

If it’s for UI reasons, we are working on adding slice methods to our query results (per this thread: https://groups.google.com/forum/#!topic/realm-cocoa/VcMfk2G8iaU). In the mean time, you should copy the results you are interested in into a separate array.

Upvotes: 6

Related Questions