1,创建
//获取路径对象
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//获取完整路径
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"下载成功.plist"];
NSMutableArray *list = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSMutableArray * list1;
if (list == nil)
{
list1 = [[NSMutableArray alloc]init];
}
else
{
list1=[[NSMutableArray alloc]initWithContentsOfFile:plistPath];
}
NSMutableDictionary *allList = [[NSMutableDictionary alloc] init];
[allList setValue:[NSString stringWithFormat:@"%@",model.name] forKey:@"ListName"];
[allList setValue:[NSString stringWithFormat:@"%@",model.destinationPath] forKey:@"ListFilePath"];
[allList setValue:[NSString stringWithFormat:@"%@",nameimage] forKey:@"ListFilePathimage"];
[list1 addObject:allList];
[list1 writeToFile:plistPath atomically:YES];
2,读取
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *dictFilePath = [path stringByAppendingPathComponent:@"下载成功.plist"];
Patharra =[NSMutableArray arrayWithContentsOfFile:dictFilePath];
3删除
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
NSString *filename=[path stringByAppendingPathComponent:@"下载成功.plist"];
NSMutableArray * muarraybn =[[NSMutableArray alloc]initWithContentsOfFile:filename];
3.1 删除整个plist文件
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:filename error:nil];
3.2 删除文件里面的某个值
[muarraybn removeObjectAtIndex:indexPath.row];
[muarraybn writeToFile:filename atomically:YES];