Additional DataStore methods
Clear
To stop DataStore sync process and to clear local data from DataStore, use the clear
method:
Amplify.DataStore.clear { result in switch result { case .success: print("DataStore cleared") case .failure(let error): print("Error clearing DataStore: \(error)") }}
Start
Synchronization starts automatically whenever you run any DataStore operation (query()
, save()
, delete()
, publisher()
.) You can also explicitly begin the process with DataStore.start()
:
Amplify.DataStore.start { result in switch result { case .success: print("DataStore started") case .failure(let error): print("Error starting DataStore: \(error)") }}
Stop
To stop the DataStore sync process, you can use DataStore.stop()
. This will close the real time subscription connection when your app is no longer interested in updates. You will typically call DataStore.stop()
just before your application is closed. You can also force your DataStore sync expressions to be re-evaluated at runtime by calling stop()
followed by start()
.
Amplify.DataStore.stop { result in switch result { case .success: print("DataStore stopped") case .failure(let error): print("Error stopping DataStore: \(error)") }}