您好,登錄后才能下訂單哦!
//路徑
+ (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];
}
//查詢(xún)
+ (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;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。