美文网首页
ios将数据保存到本地数据

ios将数据保存到本地数据

作者: 月上楼阁 | 来源:发表于2016-07-10 10:35 被阅读0次

    第一步

    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);  www.2cto.com

    NSString *path=[paths    objectAtIndex:0];

    NSLog(@"path = %@",path);

    NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];

    NSFileManager* fm = [NSFileManager defaultManager];

    [fm createFileAtPath:filename contents:nil attributes:nil];

    //NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];

    //创建一个dic,写到plist文件里

    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];

    [dic writeToFile:filename atomically:YES];

    //读文件

    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];

    NSLog(@"dic is:%@",dic2);

    相关文章

      网友评论

          本文标题:ios将数据保存到本地数据

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