写入字典,然后取出来。plist里面的可以进行替换
+(void)writDataWithDic:(NSDictionary*)dic{
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filename = [path stringByAppendingPathComponent:@"china.plist"];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createFileAtPath:path contents:nil attributes:nil];
[dic writeToFile:filename atomically:YES];
}
+(NSDictionary*)readDataWithKey:(NSString *)key{
NSString *pathp = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filenamep = [pathp stringByAppendingPathComponent:@"china.plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filenamep];
return dict[key];
}
调用
NSDictionary *dic = @{@"a":@"123",@"b":@"abc"};
[Tools writDataWithDic:dic];
NSDictionary *dicT = @{@"a":@"陪我妹电饭锅",@"345":@"电视剧九分裤"};
[Tools writDataWithDic:dicT];
NSLog(@"%@----------%@",[Tools readDataWithKey:@"a"],NSHomeDirectory());
网友评论