RLMResults
@interface RLMResults < RLMObjectType : RLMObject * > : NSObject<RLMCollection,NSFastEnumeration>
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.
-
Number of objects in the results.
Declaration
Objective‑C
@property (readonly, assign, nonatomic) NSUInteger count;
-
The class name (i.e. type) of the RLMObjects contained in this RLMResults.
Declaration
Objective‑C
@property (readonly, copy, nonatomic) NSString *_Nonnull objectClassName;
-
The Realm this
RLMResults
is associated with.Declaration
Objective‑C
@property (readonly, nonatomic) RLMRealm *_Nonnull realm;
-
Returns the object at the index specified.
Declaration
Objective‑C
- (nonnull RLMObjectType)objectAtIndex:(NSUInteger)index;
Parameters
index
The index to look up.
Return Value
An RLMObject of the type contained in this RLMResults.
-
Returns the first object in the results.
Returns
nil
if called on an empty RLMResults.Declaration
Objective‑C
- (nullable RLMObjectType)firstObject;
Return Value
An RLMObject of the type contained in this RLMResults.
-
Returns the last object in the results.
Returns
nil
if called on an empty RLMResults.Declaration
Objective‑C
- (nullable RLMObjectType)lastObject;
Return Value
An RLMObject of the type contained in this RLMResults.
-
Gets the index of an object.
Returns NSNotFound if the object is not found in this RLMResults.
Declaration
Objective‑C
- (NSUInteger)indexOfObject:(nonnull RLMObjectType)object;
Parameters
object
An object (of the same type as returned from the objectClassName selector).
-
Gets the index of the first object matching the predicate.
Declaration
Objective‑C
- (NSUInteger)indexOfObjectWhere:(nonnull 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.
-
Gets the index of the first object matching the predicate.
Declaration
Objective‑C
- (NSUInteger)indexOfObjectWithPredicate:(nonnull 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.
-
Get objects matching the given predicate in the RLMResults.
Declaration
Objective‑C
- (nonnull RLMResults<RLMObjectType> *)objectsWhere: (nonnull NSString *)predicateFormat, ...;
Parameters
predicateFormat
The predicate format string which can accept variable arguments.
Return Value
An RLMResults of objects that match the given predicate
-
Get objects matching the given predicate in the RLMResults.
Declaration
Objective‑C
- (nonnull RLMResults<RLMObjectType> *)objectsWithPredicate: (nonnull NSPredicate *)predicate;
Parameters
predicate
The predicate to filter the objects.
Return Value
An RLMResults of objects that match the given predicate
-
Get a sorted
RLMResults
from an existingRLMResults
sorted by a property.Declaration
Objective‑C
- (nonnull RLMResults<RLMObjectType> *) sortedResultsUsingProperty:(nonnull 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.
-
Get a sorted
RLMResults
from an existingRLMResults
sorted by anNSArray
of
RLMSortDescriptor`s.Declaration
Objective‑C
- (nonnull RLMResults<RLMObjectType> *)sortedResultsUsingDescriptors: (nonnull NSArray *)properties;
Parameters
properties
An array of
RLMSortDescriptor
s to sort by.Return Value
An RLMResults sorted by the specified properties.
-
Returns the minimum (lowest) value of the given property
NSNumber *min = [results minOfProperty:@"age"];
Declaration
Objective‑C
- (nullable id)minOfProperty:(nonnull 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.
-
Returns the maximum (highest) value of the given property of objects in an RLMResults
NSNumber *max = [results maxOfProperty:@"age"];
Declaration
Objective‑C
- (nullable id)maxOfProperty:(nonnull 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
-
Returns the sum of the given property for objects in an RLMResults.
NSNumber *sum = [results sumOfProperty:@"age"];
Declaration
Objective‑C
- (nonnull NSNumber *)sumOfProperty:(nonnull 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.
-
Returns the average of a given property for objects in an RLMResults.
NSNumber *average = [results averageOfProperty:@"age"];
Declaration
Objective‑C
- (nullable NSNumber *)averageOfProperty:(nonnull 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.
-
-[RLMResults init] is not available because RLMResults cannot be created directly. RLMResults can be obtained by querying a Realm.
Declaration
Objective‑C
- (nonnull instancetype)init;
-
+[RLMResults new] is not available because RLMResults cannot be created directly. RLMResults can be obtained by querying a Realm.
Declaration
Objective‑C
+ (nonnull instancetype) new;