Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.39k stars 1.91k forks source link

mmkv rootDir问题请教 #1239

Closed zlmac closed 8 months ago

zlmac commented 8 months ago

iOS 初始化,之前是默认根目录, [MMKV initializeMMKV: nil];

现在想改成自定义的根目录, [MMKV initializeMMKV: myRootDir];

改完后之前保存的数据怎么继续使用呢?

lingol commented 8 months ago

By default, MMKV stores files inside $(Documents)/mmkv/. Suppose you have "abc" in the old default directory, here's how you can read from it:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
auto libraryPath = (NSString *) [paths firstObject];
auto oldRootDir = [libraryPath stringByAppendingPathComponent:@"mmkv"];
auto mmkv = [MMKV mmkvWithID:@"abc" relativePath:oldRootDir];

For more information, https://github.com/Tencent/MMKV/wiki/iOS_advance#customize-location