【发布时间】:2017-04-12 10:41:31
【问题描述】:
我需要找到当前的 .sqlite 文件位置以进行备份;我该怎么做呢?这是我的代码,它返回“找不到文件”:
// find current directory for saori.sqlite
NSString *coreDataStorePath = [self createCoreDataStorePath];
// sqlite store setup
NSString *storePath = [coreDataStorePath stringByAppendingPathComponent:@"BookstoreInventoryManager.sqlite"]; // Application Support/SalonBook/saori.sqlite/saori.sqlite
NSLog(@"\n\nBACKUP - storePath: %@",storePath);
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: storePath])
[MagicalRecord cleanUp]; // set stack, etc to 'nil'
else {
NSLog(@"\n\n-->BookstoreInventoryManager files not found"); // log message "unable to find sqlite files
return;
}
这是createCoreDataStorePath的代码:
-(NSString *)createCoreDataStorePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *applicationSupportDirectory = [paths firstObject];
NSString *coreDataStorePath = [applicationSupportDirectory stringByAppendingPathComponent:@"/books"];
NSLog(@"\n\ncoreDataStorePath: %@", coreDataStorePath);
return coreDataStorePath;
}
我查看了 Google 和 SO,但没有找到我的答案。
【问题讨论】:
-
什么是
coreDataStorePath?你如何保存/检索它?与NSApplicationSupportDirectory?
标签: objective-c sqlite nsfilemanager magicalrecord