Managing Stores

If you create global stores, you’re required to perform cleanup when the app exits. Also, if you create multiple user stores, you can perform cleanup if you’re no longer using particular stores. SmartStore provides methods deleting named and global stores. For hybrid apps, SmartStore also provides functions for getting a list of named stores.

iOS Native Apps

Mobile SDK for iOS defines the following SFSmartStore methods for removing stores.

Swift
1func removeShared(withName: String) -> Void
2func removeShared(withName: String, forUserAccount: UserAccount) -> Void
3func removeSharedGlobal(withName: String) -> Void
4func removeAllForCurrentUser() -> Void
5func removeAll(forUserAccount: UserAccount) -> Void
6func removeAllGlobal() -> Void
Objective-C
1+ (void)removeSharedStoreWithName:(NSString *)storeName;
2+ (void)removeSharedStoreWithName:(NSString *)storeName forUser:(SFUserAccount *)user;
3+ (void)removeSharedGlobalStoreWithName:(NSString *)storeName;
4+ (void)removeAllStores;
5+ (void)removeAllStoresForUser:(SFUserAccount *)user;
6+ (void)removeAllGlobalStores;
In addition, SmartStore provides the following methods for retrieving store names. Use this method for both Swift and Objective-C apps.
1+ (NSArray *)allStoreNames;
2+ (NSArray *)allGlobalStoreNames;

Android Native Apps

Mobile SDK for Android defines the following SmartStoreSDKManager methods for removing stores.

1public void removeGlobalSmartStore(String dbName)
2public void removeSmartStore()
3public void removeSmartStore(UserAccount account)
4public void removeSmartStore(UserAccount account, String communityId)
5public void removeSmartStore(String dbNamePrefix, UserAccount account, String communityId)
In addition, SmartStore provides the following methods for retrieving store names.
1public List<String> getGlobalStoresPrefixList()
2public List<String> getUserStoresPrefixList()

Hybrid Apps

SmartStore defines the following functions for removing stores. Each function takes success and error callbacks. The removeStore() function also requires either a StoreConfig object that specifies the store name, or just the store name as a string.
1removeStore(storeConfig,successCB, errorCB)
2removeAllGlobalStores(successCB, errorCB)
3removeAllStores(successCB, errorCB)
In addition, the hybrid version of SmartStore provides the following functions for retrieving the StoreConfig objects for defined stores.
1getAllStores(successCB, errorCB)
2getAllGlobalStores(successCB, errorCB)
3getAllStores(successCB, errorCB)
4getAllGlobalStores(successCB, errorCB)

Removing All SmartStore Data at Runtime

Sometimes an app must remove all data in a store without logging out the current user. In this case, keep in mind that the sync manager object sets up a table to track syncs. If you delete this table, the manager can’t continue. Therefore, the recommended way to reset SmartStore to a zero-data state is as follows:

  1. Drop the sync managers associated with the current user.
    iOS
    Swift
    Call the following SyncManager method:
    1func removeSharedInstance(user: UserAccount) -> Void
    Objective-C
    Call the following SFMobileSyncSyncManager method:
    1+ (void)removeSharedInstance:(SFUserAccount*)user;
    Android
    Call the following MobileSyncSyncManager method:
    1public static synchronized void reset(UserAccount account)
  2. Drop the stores associated with the current user.
    iOS
    Swift
    Call the following SmartStore method:
    1func removeAll(forUserAccount: UserAccount) -> Void
    Objective-C
    Call the following SFSmartStore method:
    1+ (void)removeAllStoresForUser:(SFUserAccount *)user;
    Android
    Call the following SmartStoreSDKManager method:
    1public void removeAllUserStores()