RLMResults Class Reference
Inherits from | NSObject |
Conforms to | NSFastEnumeration RLMCollection |
Declared in | RLMResults.h RLMResults.mm |
Overview
RLMResults is an auto-updating container type in Realm returned from object queries.
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.
Tasks
RLMResults Properties
-
count
property -
objectClassName
property -
realm
property
Accessing Objects from an RLMResults
Querying Results
-
– indexOfObject:
-
– indexOfObjectWhere:
-
– indexOfObjectWithPredicate:
-
– objectsWhere:
-
– objectsWithPredicate:
-
– sortedResultsUsingProperty:ascending:
-
– sortedResultsUsingDescriptors:
Aggregating Property Values
Unavailable Methods
Other Methods
Properties
count
Number of objects in the results.
@property (nonatomic, readonly, assign) NSUInteger count
Declared In
RLMResults.h
Class Methods
new
[RLMResults new] is not available because RLMResults cannot be created directly. RLMResults can be obtained by querying a Realm.
+ (instancetype)new
Declared In
RLMResults.h
Instance Methods
averageOfProperty:
Returns the average of a given property for objects in an RLMResults.
- (NSNumber *)averageOfProperty:(NSString *)property
Parameters
- property
The property to calculate average on. Only properties of type int, float and double are supported.
Return Value
The average for the given property amongst objects in an RLMResults. This will be of type double for both float and double properties.
Discussion
NSNumber *average = [results averageOfProperty:@“age”];
Declared In
RLMResults.h
firstObject
Returns the first object in the results.
- (id)firstObject
Return Value
An RLMObject of the class contained by this RLMResults.
Discussion
Returns nil
if called on an empty RLMResults.
Declared In
RLMResults.h
indexOfObject:
Gets the index of an object.
- (NSUInteger)indexOfObject:(RLMObject *)object
Parameters
- object
An object (of the same type as returned from the objectClassName selector).
Discussion
Returns NSNotFound if the object is not found in this RLMResults.
Declared In
RLMResults.h
indexOfObjectWhere:
Gets the index of the first object matching the predicate.
- (NSUInteger)indexOfObjectWhere:(NSString *)predicateFormat, ...
Parameters
- predicateFormat
The predicate format string which can accept variable arguments.
Return Value
Index of object or NSNotFound if the object is not found in this RLMResults.
Declared In
RLMResults.h
indexOfObjectWithPredicate:
Gets the index of the first object matching the predicate.
- (NSUInteger)indexOfObjectWithPredicate:(NSPredicate *)predicate
Parameters
- predicate
The predicate to filter the objects.
Return Value
Index of object or NSNotFound if the object is not found in this RLMResults.
Declared In
RLMResults.h
init
[RLMResults init] is not available because RLMResults cannot be created directly. RLMResults can be obtained by querying a Realm.
- (instancetype)init
Declared In
RLMResults.h
lastObject
Returns the last object in the results.
- (id)lastObject
Return Value
An RLMObject of the class contained by this RLMResults.
Discussion
Returns nil
if called on an empty RLMResults.
Declared In
RLMResults.h
maxOfProperty:
Returns the maximum (highest) value of the given property of objects in an RLMResults
- (id)maxOfProperty:(NSString *)property
Parameters
- property
The property to look for a maximum on. Only properties of type int, float, double and NSDate are supported.
Return Value
The maximum value for the property amongst objects in an RLMResults
Discussion
NSNumber *max = [results maxOfProperty:@“age”];
Declared In
RLMResults.h
minOfProperty:
Returns the minimum (lowest) value of the given property
- (id)minOfProperty:(NSString *)property
Parameters
- property
The property to look for a minimum on. Only properties of type int, float, double and NSDate are supported.
Return Value
The minimum value for the property amongst objects in an RLMResults.
Discussion
NSNumber *min = [results minOfProperty:@“age”];
Declared In
RLMResults.h
objectAtIndex:
Returns the object at the index specified.
- (id)objectAtIndex:(NSUInteger)index
Parameters
- index
The index to look up.
Return Value
An RLMObject of the class contained by this RLMResults.
Declared In
RLMResults.h
objectsWhere:
Get objects matching the given predicate in the RLMResults.
- (RLMResults *)objectsWhere:(NSString *)predicateFormat, ...
Parameters
- predicateFormat
The predicate format string which can accept variable arguments.
Return Value
An RLMResults of objects that match the given predicate
Declared In
RLMResults.h
objectsWithPredicate:
Get objects matching the given predicate in the RLMResults.
- (RLMResults *)objectsWithPredicate:(NSPredicate *)predicate
Parameters
- predicate
The predicate to filter the objects.
Return Value
An RLMResults of objects that match the given predicate
Declared In
RLMResults.h
setValue:forKey:
Invokes setValue:forKey:
on each of the collection’s objects using the specified value and key.
- (void)setValue:(id)value forKey:(NSString *)key
Parameters
- value
The object value.
- key
The name of the property.
Discussion
Warning: This method can only be called during a write transaction.
Declared In
RLMCollection.h
sortedResultsUsingDescriptors:
Get a sorted RLMResults
from an existing RLMResults
sorted by an NSArray`` of
RLMSortDescriptor`s.
- (RLMResults *)sortedResultsUsingDescriptors:(NSArray *)properties
Parameters
- properties
An array of
RLMSortDescriptor
s to sort by.
Return Value
An RLMResults sorted by the specified properties.
Declared In
RLMResults.h
sortedResultsUsingProperty:ascending:
Get a sorted RLMResults
from an existing RLMResults
sorted by a property.
- (RLMResults *)sortedResultsUsingProperty:(NSString *)property ascending:(BOOL)ascending
Parameters
- property
The property name to sort by.
- ascending
The direction to sort by.
Return Value
An RLMResults sorted by the specified property.
Declared In
RLMResults.h
sumOfProperty:
Returns the sum of the given property for objects in an RLMResults.
- (NSNumber *)sumOfProperty:(NSString *)property
Parameters
- property
The property to calculate sum on. Only properties of type int, float and double are supported.
Return Value
The sum of the given property over all objects in an RLMResults.
Discussion
NSNumber *sum = [results sumOfProperty:@“age”];
Declared In
RLMResults.h
valueForKey:
Returns an NSArray containing the results of invoking valueForKey:
using key on each of the collection’s objects.
- (id)valueForKey:(NSString *)key
Parameters
- key
The name of the property.
Return Value
NSArray containing the results of invoking valueForKey:
using key on each of the collection’s objects.
Declared In
RLMCollection.h