iOSplist文件的增删,改查

//路径

创新互联建站网站建设提供从项目策划、软件开发,软件安全维护、网站优化(SEO)、网站分析、效果评估等整套的建站服务,主营业务为成都网站建设、成都做网站,app软件开发公司以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。创新互联建站深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

+ (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;

}

当前题目:iOSplist文件的增删,改查
文章出自:https://www.cdcxhl.com/article20/ihhgco.html

成都网站建设公司_创新互联,为您提供网站建设外贸网站建设标签优化网站策划网站导航网站内链

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作