How can I easily delete all objects in a Realm

后端 未结 4 2099
轮回少年
轮回少年 2020-12-09 01:41

I have the choice of doing a migration, but I would prefer to delete everything in my defaultRealm(). How can I do this easily?

realm.deleteObject(object)
         


        
4条回答
  •  余生分开走
    2020-12-09 02:09

    Things have moved on in the Realm world - in case anyone comes across this now, there is a property that can be set:

    Realm.Configuration.defaultConfiguration.deleteRealmIfMigrationNeeded = true
    

    It then does as advertised. (btw: a lot of the syntax above has changed in case you are trying any of the other methods)

    The Github PR https://github.com/realm/realm-cocoa/pull/3463

提交回复
热议问题