新聞中心
//路徑

+ (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;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
文章名稱:iOSplist文件的增刪,改查-創(chuàng)新互聯(lián)
文章URL:http://www.dlmjj.cn/article/ddiihj.html


咨詢
建站咨詢
