NSString *filePath = [[NSBundle mainBundle] pathForResource:@"config_region" ofType:@"csv"];

    NSString *text = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

 

    NSMutableArray *marr = [NSMutableArray array];

    // 改行文字で区切って配列に格納する

    NSArray *lines = [text componentsSeparatedByString:@"\n"];

    

    for (NSString *row in lines) {

        // コンマで区切って配列に格納する

        NSArray *items = [row componentsSeparatedByString:@","];

        if (items.count > 1) {

            NSDictionary *item = [[NSDictionary alloc]

                                  initWithObjects:@[items[0],items[1]]

                                  forKeys:@[@"name",@"class"]];

            [marr addObject:item];

        }

    }

    

    //STEP 2

    // ホームディレクトリを取得

    NSString *homeDir = NSHomeDirectory();

    NSString *fileName = @"hoge.plist";

    // 書き込み

    BOOL result = [marr writeToFile:[homeDir stringByAppendingPathComponent:fileName]

                         atomically:YES];

    if (!result) {

        NSLog(@"ファイルの書き込みエラー");

    }else{

        NSLog(@"ファイルの書き込み成功");

    }

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2021-09-06
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-16
  • 2021-04-03
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-08-22
相关资源
相似解决方案