Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-1098

move(fromOffsets:toOffset) crashes for Lists of EmbeddedObjects

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Moving embedded objects through the offset API crashes. Here's a simple reproduction case:

      func testEmbeddedListMove() {
          let parentObject = EmbeddedParentObject()
          for _ in 0..<3 {
              parentObject.array.append(EmbeddedTreeObject1())
          }
      
          // unmanaged is OK
          parentObject.array.move(fromOffsets: IndexSet([0]), toOffset: 1)
      
          let realm = inMemoryRealm("swiftui-tests")
          try! realm.write {
              realm.add(parentObject)
          }
          try! realm.write {
              // standard move with managed is ok
              parentObject.array.move(from: 0, to: 1)
          }
          try! realm.write {
              // offset move with managed is not ok, Cannot add an existing managed embedded object to a List, this will crash
              parentObject.array.move(fromOffsets: IndexSet([0]), toOffset: 1)
          }
      }
      

            Assignee:
            jason.flax@mongodb.com Jason Flax
            Reporter:
            jason.flax@mongodb.com Jason Flax
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: