iOS plist

//存

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

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

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

    NSDictionary* dic = @{@"image":str};

    NSLog(@"dic----%@",dic);

    [dic writeToFile:filename atomically:YES];

 

//取

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

    NSString *path=[paths objectAtIndex:0];

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

    NSDictionary* dic2 = [NSDictionary dictionaryWithContentsOfFile:filename];

    NSLog(@"dic2---%@",dic2);

posted @ 2016-05-27 13:11  tongyuling  阅读(112)  评论(0编辑  收藏  举报