question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `Realm.delete(RealmList)` and `Realm.delete(RealmResults) to remove RealmObjects

See original GitHub issue

Cocoa binding has the similar functions See https://realm.io/docs/swift/latest/api/Classes/Realm.html#/s:FC10RealmSwift5Realm6deleteuRq_Ss12SequenceTypedqqq_S1_9GeneratorSs13GeneratorType7ElementCS_6Object_FS0_Fq_T_

Currently, All objects in RealmResults can be deleted by RealmResults.clear() But there is no function to delete all objects from RealmList

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Oct 9, 2015

We probably need to consider our whole API in this area, as right now it isn’t as clear as one could hope IMO. I think the original idea was to stick as close to the Java Collection API methods as possible, which makes a lot of sense. However, how they work differ based on the type, which makes the API harder to understand:

realm.clear(clazz); // Deletes all objects of a given type from the Realm

realmResults.clear(); // Deletes all query results from the Realm
realmResults.remove(int location); // Removes item from Realm, returns null
realmResults.removeLast(); Removes last item from Realm
// Why no removeFirst?

realmList.clear(); // Removes items from the List, but not Realm
realmList.remove(int location); // Removes items from the List, but not Realm. Returns item
// Why no removeLast/First?

realmObject.removeFromRealm(); // Removes the object from Realm. isValid() now returns false.

Maybe it would make more sense to use the RealmList semantics everywhere? That would be more inline with Java semantics, would allow people to manipulate the results outside a write transaction, and would allow people to up-cast RealmResults to List without problems.

Given that you need a write-transaction anyway to actually delete the Realm data. Adding special methods for removing would probably be cleaner?

realm.removeFromRealm(obj)
realm.removeFromRealm(collection);

realmResults.removeLastFromRealm()
realmResults.removeFromRealm(int location)
realmResults.removeAllFromRealm();

realmList.removeFromRealm(int location)
realmList.removeAllFromRealm();

Objective C uses delete* instead of remove*. Something worth considering if we moved away from the collection API methods anyway.

What do you think?

0reactions
nicks258commented, Jun 6, 2016

it says cannot resolve method ‘deleteAll()’ when i am using Realm.deleteAll()

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I delete Realm objects which are not referenced by ...
Then you can delete any objects where: RealmResults<Direction> unusedDirections = realm.where(Direction.class).isEmpty("routes").findAll();.
Read more >
Read & Write Data - Java SDK — Realm - MongoDB
To delete an object from a realm, use the deleteAllFromRealm() method of the RealmResults instance that contains the objects you would like to...
Read more >
Realm Database on Android: Getting Started
Over the course of this tutorial, you'll learn about: Realm database; Schema and entities; Inserting objects; Querying and deleting objects ...
Read more >
Integrating Realm Database in an Android Application - Auth0
You can delete the Realm file with the following code in the TaskListApplication . Remember to remove the Realm.deleteRealm(realmConfig) ...
Read more >
Create reactive mobile apps in a fraction of the time - Realm
Step 1: Add the following class path dependency to the project level build.gradle ... Setting the RealmObject field to null will clear the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found