Wrong result in Results<Element> observation


#1

In .update case of observation sometimes there are incorrect indexes in insertions and modifications. Example - when I’m trying to work with objects at indexes (insertions or modifications) in newly observed collection I am geting index out of bounds crash.

realm.objects(SomeObject.self)
            .filter(predicate)
            .observe { [weak self] change in
                guard let self = self else { return }
                
                switch change {
                case .update(let result, _, let insertions, _):
                    self.performInsertionUpdates(with: insertions.map { result[$0].id })
                    
                default:
                    break
                }
            }

Here is example with prints -

            case .update(let results, let deletions, let insertions, let modifications):
                print("result count \(results.count)")
                print("deletions - \(deletions)")
                print("insertions - \(insertions)")
                print("modifications - \(modifications)")
result count 1
deletions - []
insertions - [0]
modifications - []

result count 0
deletions - [0]
insertions - []
modifications - []

result count 1
deletions - []
insertions - [0]
modifications - []

result count 2
deletions - []
insertions - [1, 2, 3, 4, 5]
modifications - []