1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2016 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #import <Realm/RLMCollection_Private.h>
27 struct CollectionChangeSet;
28 struct NotificationToken;
31 @class RLMFastEnumerator;
33 @protocol RLMFastEnumerable
34 @property (nonatomic, readonly) RLMRealm *realm;
35 @property (nonatomic, readonly) RLMClassInfo *objectInfo;
36 @property (nonatomic, readonly) NSUInteger count;
38 - (realm::TableView)tableView;
39 - (RLMFastEnumerator *)fastEnumerator;
42 // An object which encapulates the shared logic for fast-enumerating RLMArray
43 // and RLMResults, and has a buffer to store strong references to the current
44 // set of enumerated items
45 @interface RLMFastEnumerator : NSObject
46 - (instancetype)initWithList:(realm::List&)list
47 collection:(id)collection
48 realm:(RLMRealm *)realm
49 classInfo:(RLMClassInfo&)info;
50 - (instancetype)initWithResults:(realm::Results&)results
51 collection:(id)collection
52 realm:(RLMRealm *)realm
53 classInfo:(RLMClassInfo&)info;
55 // Detach this enumerator from the source collection. Must be called before the
56 // source collection is changed.
59 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
60 count:(NSUInteger)len;
62 NSUInteger RLMFastEnumerate(NSFastEnumerationState *state, NSUInteger len, id<RLMFastEnumerable> collection);
64 @interface RLMNotificationToken ()
65 - (void)suppressNextNotification;
69 @interface RLMCancellationToken : RLMNotificationToken
70 - (instancetype)initWithToken:(realm::NotificationToken)token realm:(RLMRealm *)realm;
73 @interface RLMCollectionChange ()
74 - (instancetype)initWithChanges:(realm::CollectionChangeSet)indices;
77 template<typename Collection>
78 RLMNotificationToken *RLMAddNotificationBlock(id objcCollection,
79 Collection& collection,
80 void (^block)(id, RLMCollectionChange *, NSError *),
81 bool suppressInitialChange=false);
83 template<typename Collection>
84 NSArray *RLMCollectionValueForKey(Collection& collection, NSString *key,
85 RLMRealm *realm, RLMClassInfo& info);
87 std::vector<std::pair<std::string, bool>> RLMSortDescriptorsToKeypathArray(NSArray<RLMSortDescriptor *> *properties);