Skip to content

Commit

Permalink
Fix assersion failure when moving objects between sections
Browse files Browse the repository at this point in the history
  • Loading branch information
ngs committed Jun 2, 2016
1 parent 7426d08 commit e8e4022
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions RBQFetchedResultsController/Source/RBQFetchedResultsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ - (NSSet *)safeObjectsFromChanges:(NSArray<NSNumber *> *)changes
safeObject = [RBQSafeRealmObject safeObjectFromObject:object];
}
else {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstObjectIndex <= %@ AND lastObjectIndex >= %@", index, index];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstObjectIndex <= %@ AND lastObjectIndex >= %@ AND objects.@count > 0", index, index];
RLMResults *sections = [RBQSectionCacheObject objectsInRealm:cacheRealm withPredicate:predicate];
RBQSectionCacheObject *section = sections.firstObject;
NSUInteger row = index.unsignedIntegerValue - section.firstObjectIndex;
Expand Down Expand Up @@ -891,7 +891,7 @@ - (void)applyDerivedChangesToCache:(RBQDerivedChangesObject *)derivedChanges
for (NSOrderedSet *objectChanges in @[derivedChanges.deletedObjectChanges,
derivedChanges.insertedObjectChanges,
derivedChanges.movedObjectChanges]) {

for (RBQObjectChangeObject *objectChange in objectChanges) {

if (objectChange.changeType == NSFetchedResultsChangeDelete) {
Expand All @@ -915,12 +915,12 @@ - (void)applyDerivedChangesToCache:(RBQDerivedChangesObject *)derivedChanges
RBQSectionCacheObject *section =
[RBQSectionCacheObject objectInRealm:state.cacheRealm
forPrimaryKey:objectChange.updatedCacheObject.sectionKeyPathValue];

#ifdef DEBUG
NSAssert(objectChange.updatedIndexpath.row <= section.objects.count, @"Attemting to insert at index beyond bounds!");
#endif
NSInteger insertIndex = objectChange.updatedIndexpath.row;
if (insertIndex >= section.objects.count) {
insertIndex = section.objects.count - 1;
}
[section.objects insertObject:objectChange.updatedCacheObject
atIndex:objectChange.updatedIndexpath.row];
atIndex:insertIndex];

objectChange.updatedCacheObject.section = section;
}
Expand Down

0 comments on commit e8e4022

Please sign in to comment.