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];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值