持久化存储文件在文件系统中的位置
- 先获取应用程序文档目录的路径
-
#pragma mark - PATHS- (NSString *)applicationDocumentsDirectory { if (debug == 1) { NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd)); } return [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject];}
-
- 返回包含Stores的子目录路径的NSURL,如果没有则创建
-
- (NSURL *)applicationStoresDirectory { if (debug == 1) { NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd)); } NSURL *storesDirectory = [[NSURL fileURLWithPath:[self applicationDocumentsDirectory]] URLByAppendingPathComponent:@"Stores"]; NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:[storesDirectory path]]) { NSError *error = nil; if ([fileManager createDirectoryAtURL:storesDirectory withIntermediateDirectories:YES attributes:nil error:&error]) { if (debug == 1) { NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd)); }else{ NSLog(@"FAILD to Create Stores directory:%@",error); } } } return storesDirectory;}
-
- 返回完整路径
-
- (NSURL *)storeURL { if (debug == 1) { NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd)); } return [[self applicationStoresDirectory] URLByAppendingPathComponent:storeFilename];}
-