@siddharth_kamaria Super good info. Thanks for those links. Here’s another option for a client reset that’s not directly related to the original question.
Realm fixed the built in functionality for a client reset which doesn’t rely on the FileManager or storing information in User Defaults. It’s a matter of clearing the files stored of disk associated with each partition. Let me set this up (Swift).
Generally, an app will have a Constants file (per the documetation) which may store your Realm Partitions - like this
import RealmSwift
struct Constants {
// Set this to your Realm App ID found in the Realm UI.
static let REALM_APP_ID = "tasktracker-xyzab"
static let REALM_PARTITION_VALUE = "Task Tracker"
static let JAY_PARTITION_VALUE = "Jay Task"
static let CINDY_PARTITION_VALUE = "Cindy Task"
}
So in this Task Tracker app, there are three partitions; a main Task, my task and Cindys tasks.
Then to do a client reset those three partitions need to be removed from disk;
func performDelete() {
//let user = get the current user object.
self.deletePartitionFilesFor(user: user, whichPartition: Constants.REALM_PARTITION_VALUE)
self.deletePartitionFilesFor(user: user, whichPartition: Constants.JAY_PARTITION_VALUE)
self.deletePartitionFilesFor(user: user, whichPartition: Constants.CINDY_PARTITION_VALUE)
}
which calls this function which relies on Realm.deleteFiles:for
func deletePartitionFilesFor(user: User, whichPartition: String) {
do {
let config = user.configuration(partitionValue: whichPartition)
let result = try Realm.deleteFiles(for: config)
if result == true {
print(" all files have been deleted")
} else {
print(" deleting of files failed, it's probably open or the files were already deleted")
}
} catch let error as NSError {
print(error.localizedDescription)
}
}
This will not delete the .lock files but those don’t contain any sync’d data.
Also, and this is critical, for the above code to work the app cannot have already accessed Realm. e.g. once the app ‘touches’ Realm, those files cannot be deleted. So the code would need to be run before any Realm calls are made.
To tie this back to one part of the original question
you can’t just wipe user’s data because you added a field in an object can you?
As it stands, additive changes happen automatically. So if a property is added to an object, it will (eventually) show up in the console->realm->app name->schema section and when a new object is written, it will show up in the Collections area.
We’re not so lucky with destructive changes. The change will have to be made and the client will have to be ‘reset’ (wiped) per the above, and allow it to re-sync. There is no built in mechanism for this (HELLO REALM) so you’ll have to manually write the code to make that happen.
The documentation avoids this topic entirely in sync situations.