美文网首页iOS
关于Plist的写入与读取

关于Plist的写入与读取

作者: 三浦蒼介 | 来源:发表于2018-10-31 09:04 被阅读0次

    -(void)write

    {

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSString* path = [pathsobjectAtIndex:0];

        NSString*Files =@"Account";

        NSFileManager * fm = [NSFileManager defaultManager];

        NSString *filePath =[NSString stringWithFormat:@"%@/%@",path,Files];

        if(![fmfileExistsAtPath:filePath]) {

            [fmcreateDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];

        }

    NSString * docDir = [filePath stringByAppendingPathComponent:@"************.plist"];  NSMutableDictionary *loaddic = [NSMutableDictionary dictionaryWithContentsOfFile:docDir]; NSMutableDictionary* userdic = [NSMutableDictionary dictionaryWithDictionary:loaddic[****]];

        [userdic setObject:@"0" forKey:@"*****"];

        for(id keyName in [load dicallKeys]) {

            if([mobilNumberisEqualToString:keyName]){

                loaddic[*****] = [NSMutableDictionarydictionaryWithDictionary:userdic];

            }

        }

        [loaddic writeToFile:docDir atomically:YES];

    }

    - (NSMutableDictionary*)read

    {

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSString*path = [pathsobjectAtIndex:0];

        NSString*Files =@"Account";

        NSFileManager *fm = [NSFileManager defaultManager];

        NSString *filePath =[NSString stringWithFormat:@"%@/%@",path,Files];

        if(![fmfileExistsAtPath:filePath]) {

            [fmcreateDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];

        }

        NSString *docDir = [filePath stringByAppendingPathComponent:@"************.plist"];

        NSMutableDictionary *loadDic = [NSMutableDictionary dictionaryWithContentsOfFile:docDir];

        returnloadDic;

    }

    相关文章

      网友评论

        本文标题:关于Plist的写入与读取

        本文链接:https://www.haomeiwen.com/subject/qyxgtqtx.html