zoukankan      html  css  js  c++  java
  • 1.4.2.2. PATHS(Core Data 应用程序实践指南)

      持久化存储文件在文件系统中的位置

    1. 先获取应用程序文档目录的路径
      1. #pragma mark - PATHS
        - (NSString *)applicationDocumentsDirectory {
            if (debug == 1) {
                NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
            }
            
            return [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject];
        }
    2. 返回包含Stores的子目录路径的NSURL,如果没有则创建
      1. - (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;
        }
    3. 返回完整路径
      1. - (NSURL *)storeURL {
            if (debug == 1) {
                NSLog(@"Running %@ '%@'",self.class, NSStringFromSelector(_cmd));
            }
            return [[self applicationStoresDirectory] URLByAppendingPathComponent:storeFilename];
        }
  • 相关阅读:
    host 文件位置
    Django 前后端分离开发配置 跨域
    pycharm 关闭单词拼写检查(Typo: In word 'cacheable' )
    Python : argument name should be lowercase 警告处理解决方法
    pycharm 变量名 (Shadows built-in name 'id' )问题
    三体
    12.URL下载网络资源
    11.UDP多线程在线咨询
    10.UDP实现聊天
    9.UDP
  • 原文地址:https://www.cnblogs.com/SimonGao/p/4928625.html
Copyright © 2011-2022 走看看