zoukankan      html  css  js  c++  java
  • plist文件操作

    直接将项目中用到的对plist文件处理的部分拿出来:

    //向草稿箱中写如数据
    - (void)writeToSendedList:(NSString *)message{
    
        //沙盒中的目录
        NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *doucumentsDirectiory = [storeFilePath objectAtIndex:0];
        NSLog(@"doucumentsDirectiory:%@",doucumentsDirectiory);
        NSString *plistPath =[doucumentsDirectiory stringByAppendingPathComponent:@"MessageList.plist"];
        if( [[NSFileManager defaultManager] fileExistsAtPath:[doucumentsDirectiory stringByAppendingPathComponent:@"MessageList.plist"]]==NO ) {
            // ============================== 写入plist初始化数据 ===========================
            NSMutableDictionary *messageList = [[NSMutableDictionary alloc] init];
            
            
            NSMutableDictionary *sendedList = [[NSMutableDictionary alloc] init];
            NSMutableArray *hztest01Sended = [[NSMutableArray alloc] initWithObjects:@"123",@"12222",@"fox", nil];
            [sendedList  setObject:hztest01Sended forKey:@"hztest01"];
            
            
            NSMutableDictionary *draftsList = [[NSMutableDictionary alloc] init];
            NSMutableArray *hztest01Drafts = [[NSMutableArray alloc] initWithObjects:@"123",@"12222",@"fox", nil];
            [draftsList  setObject:hztest01Drafts forKey:@"hztest01"];
            
            
            [messageList setObject:sendedList forKey:@"DraftsList"];
            [messageList  writeToFile:plistPath atomically:YES];
        }
        
        
        
        
        
        //非沙盒中的目录
        //NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"SendedList"ofType:@"plist"];
        
        NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; 
        NSMutableDictionary *mydictionary = [[NSMutableDictionary alloc] initWithDictionary:[dictionary objectForKey:@"SendedList"]];
        NSMutableArray *mysendedList = [[NSMutableArray alloc] initWithArray:[mydictionary objectForKey:@"hztest01"]];
        NSLog(@"hztest01的发送箱:%@",mysendedList);
     
        [mysendedList addObject:message];
        
        
        [mydictionary removeObjectForKey:@"hztest01"];
        [mydictionary setObject:mysendedList forKey:@"hztest01"];
        [dictionary setObject:mydictionary forKey:@"SendedList"];
        [dictionary writeToFile:plistPath atomically:YES];
        
        
        [mysendedList release];
        [mydictionary release];
        [dictionary release];
    
    }
  • 相关阅读:
    BZOJ2301——莫比乌斯&&整除分块
    2019HDU多校第五场A fraction —— 辗转相除法|类欧几里得
    AKS素性检测
    2019牛客多校B generator 1——十进制快速幂
    BZOJ 3884——欧拉降幂和广义欧拉降幂
    libevent HTTP client 的实现
    google proto buffer安装和简单示例
    setenv LD_LIBRARY_PATH
    Centos6.4下安装protobuf及简单使用
    lrzsz
  • 原文地址:https://www.cnblogs.com/foxmin/p/2578214.html
Copyright © 2011-2022 走看看