RLMCollection
@protocol RLMCollection <NSFastEnumeration>
A homogenous collection of RLMObjects like RLMArray or RLMResults.
-
Number of objects in the collection.
Declaration
Objective‑C
@required @property (readonly, assign, nonatomic) NSUInteger count; -
The class name (i.e. type) of the RLMObjects contained in this RLMCollection.
Declaration
Objective‑C
@required @property (readonly, copy, nonatomic) NSString *_Nonnull objectClassName; -
The Realm in which this collection is persisted. Returns nil for standalone collections.
Declaration
Objective‑C
@required @property (readonly, nonatomic) RLMRealm *_Nonnull realm;
-
Returns the object at the index specified.
Declaration
Objective‑C
- (nonnull id)objectAtIndex:(NSUInteger)index;Parameters
indexThe index to look up.
Return Value
An RLMObject of the type contained in this RLMCollection.
-
Returns the first object in the collection.
Returns
nilif called on an empty RLMCollection.Declaration
Objective‑C
- (nullable id)firstObject;Return Value
An RLMObject of the type contained in this RLMCollection.
-
Returns the last object in the collection.
Returns
nilif called on an empty RLMCollection.Declaration
Objective‑C
- (nullable id)lastObject;Return Value
An RLMObject of the type contained in this RLMCollection.
-
Gets the index of an object.
Returns NSNotFound if the object is not found in this RLMCollection.
Declaration
Objective‑C
- (NSUInteger)indexOfObject:(nonnull RLMObject *)object;Parameters
objectAn 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
predicateFormatThe predicate format string which can accept variable arguments.
Return Value
Index of object or NSNotFound if the object is not found in this RLMCollection.
-
Gets the index of the first object matching the predicate.
Declaration
Objective‑C
- (NSUInteger)indexOfObjectWithPredicate:(nonnull NSPredicate *)predicate;Parameters
predicateThe predicate to filter the objects.
Return Value
Index of object or NSNotFound if the object is not found in this RLMCollection.
-
Get objects matching the given predicate in the RLMCollection.
Declaration
Objective‑C
- (nonnull RLMResults *)objectsWhere:(nonnull NSString *)predicateFormat, ...;Parameters
predicateFormatThe 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 RLMCollection.
Declaration
Objective‑C
- (nonnull RLMResults *)objectsWithPredicate:(nonnull NSPredicate *)predicate;Parameters
predicateThe predicate to filter the objects.
Return Value
An RLMResults of objects that match the given predicate
-
Get a sorted RLMResults from an RLMCollection.
Declaration
Objective‑C
- (nonnull RLMResults *)sortedResultsUsingProperty:(nonnull NSString *)property ascending:(BOOL)ascending;Parameters
propertyThe property name to sort by.
ascendingThe direction to sort by.
Return Value
An RLMResults sorted by the specified property.
-
Get a sorted RLMResults from an RLMCollection.
Declaration
Objective‑C
- (nonnull RLMResults *)sortedResultsUsingDescriptors: (nonnull NSArray<RLMSortDescriptor *> *)properties;Parameters
propertiesAn array of
RLMSortDescriptors to sort by.Return Value
An RLMResults sorted by the specified properties.
-
Returns an NSArray containing the results of invoking
valueForKey:using key on each of the collection’s objects.Declaration
Objective‑C
- (nullable id)valueForKey:(nonnull NSString *)key;Parameters
keyThe name of the property.
Return Value
NSArray containing the results of invoking
valueForKey:using key on each of the collection’s objects. -
Invokes
setValue:forKey:on each of the collection’s objects using the specified value and key.Warning
This method can only be called during a write transaction.
Declaration
Objective‑C
- (void)setValue:(nullable id)value forKey:(nonnull NSString *)key;Parameters
valueThe object value.
keyThe name of the property.
View on GitHub
Install in Dash
RLMCollection Protocol Reference