How to delete objects in Realm?

The exception in Realm seems to be incredibly underestimated ... or am I missing something? How to remove objects from the list? Where are the examples?

I have an object A with a list. I have another object B also with a list C has a link back to its parent A

I want to delete B and all its sub-objects of C. If I delete C, I also want to remove it from my parent collection A.

I'm at a standstill ... and I find it unbelievable that Realm docs provide only two examples:

try! realm.write {
  realm.delete(cheeseBook)
}
try! realm.write {
  realm.deleteAll()
}
+4
source share
1 answer

, . Realm , , .

class C: Object {
    let parent = LinkingObjects(fromType: A.self, property: "c")
}

Realm ( ), , List . , .

let childObjects = b.subObjects
try! realm.write {
    realm.delete(childObjects)
    realm.delete(b)
}

( , , - Swift- )

Object, List, C A.

, ! , Realm.:)

+7

Source: https://habr.com/ru/post/1655134/


All Articles