Skip to content

Commit 26cfce1

Browse files
committed
Move to index 0 if previousChildKey is not found
1 parent 70d8753 commit 26cfce1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

FirebaseDatabaseUI/FirebaseArray.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ - (void)initListeners {
123123
NSUInteger fromIndex = [self indexForKey:snapshot.key];
124124
[self.snapshots removeObjectAtIndex:fromIndex];
125125

126-
NSUInteger toIndex = [self indexForKey:previousChildKey] + 1;
126+
NSUInteger toIndex = 0;
127+
NSUInteger prevIndex = [self indexForKey:previousChildKey];
128+
if (prevIndex != NSNotFound) {
129+
toIndex = prevIndex + 1;
130+
}
127131
[self.snapshots insertObject:snapshot atIndex:toIndex];
128132

129133
if ([self.delegate respondsToSelector:@selector(array:didMoveObject:fromIndex:toIndex:)]) {

0 commit comments

Comments
 (0)