我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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文件的增删,改查
文章出自:http://shouzuofang.com/article/ihhgco.html

其他资讯