//路径
+ (NSString *)cretableName
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [path objectAtIndex:0];
//指定新建文件夹路径
NSString *p_w_picpathDocPath = [documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"setPlace.plist"]];
return p_w_picpathDocPath;
}
//添加
+ (void)addPlaceWrite:(NSDictionary *)dict anCity:(NSString *)cityName
{
NSString *filePath = [self cretableName];
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if(nil == dic)
{
dic = [NSMutableDictionary dictionaryWithCapacity:0];
}
NSMutableArray *dataArry = [dic valueForKey:cityName];
if(nil == dataArry)
{
dataArry = [NSMutableArray arrayWithCapacity:0];
}
if (0 == dataArry.count)
{
[dataArry addObject:dict];
}
else
{
[dataArry addObject:dict];
}
[dic setValue:dataArry forKey:cityName];
[dic writeToFile:filePath atomically:YES];
}
//所有
+ (NSArray *)allPlaceData:(NSString *)cityName
{
NSString *filePath = [self cretableName];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSArray *aray = dict[cityName];
return aray;
}
//删除
+ (void)deletePlaceData:(NSInteger)index anCity:(NSString *)cityName
{
NSString *filePath = [self cretableName];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSMutableArray *arry = dict[cityName];
[arry removeObjectAtIndex:index];
[dict setValue:arry forKey:cityName];
[dict writeToFile:filePath atomically:YES];
}
//修改
+ (void)modifyPlaceData:(NSDictionary *)dic anPlace:(NSInteger)index anCity:(NSString *)cityName
{
NSString *filePath = [self cretableName];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSMutableArray *arry = dict[cityName];
[arry removeObjectAtIndex:index];
[arry insertObject:dic atIndex:index];
[dict setValue:arry forKey:cityName];
[dict writeToFile:filePath atomically:YES];
}
//查询
+ (BOOL)allCity:(NSString *)anCity
{
BOOL isBlean = NO;
NSString *filePath = [self cretableCityName];
NSArray *arry = [NSArray arrayWithContentsOfFile:filePath];
for(NSString *city in arry)
{
if([anCity isEqualToString:city])
{
isBlean = YES;
break;
}
}
return isBlean;
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。