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.

Properties

count

Number of objects in the results.

@property (nonatomic, readonly, assign) NSUInteger count

Declared In

RLMResults.h

objectClassName

The class name (i.e. type) of the RLMObjects contained in this RLMResults.

@property (nonatomic, readonly, copy) NSString *objectClassName

Declared In

RLMResults.h

realm

The Realm this RLMResults is associated with.

@property (nonatomic, readonly) RLMRealm *realm

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.

- (nullable 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”];

Warning: You cannot use this method on RLMObject, RLMArray, and NSData properties.

Declared In

RLMResults.h

firstObject

Returns the first object in the results.

- (nullable RLMObjectType)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:(RLMObjectArgument)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.

- (nullable RLMObjectType)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

- (nullable 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”];

Warning: You cannot use this method on RLMObject, RLMArray, and NSData properties.

Declared In

RLMResults.h

minOfProperty:

Returns the minimum (lowest) value of the given property

- (nullable 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”];

Warning: You cannot use this method on RLMObject, RLMArray, and NSData properties.

Declared In

RLMResults.h

objectAtIndex:

Returns the object at the index specified.

- (RLMObjectType)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 RLM_GENERIC_RETURN *)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 RLM_GENERIC_RETURN *)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

sortedResultsUsingDescriptors:

Get a sorted RLMResults from an existing RLMResults sorted by an NSArray`` ofRLMSortDescriptor`s.

- (RLMResults RLM_GENERIC_RETURN *)sortedResultsUsingDescriptors:(NSArray *)properties

Parameters

properties

An array of RLMSortDescriptors 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 RLM_GENERIC_RETURN *)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”];

Warning: You cannot use this method on RLMObject, RLMArray, and NSData properties.

Declared In

RLMResults.h