zoukankan      html  css  js  c++  java
  • iOS 开发,csv 转 plist

        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:@" "];

        

        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(@"ファイルの書き込み成功");

        }

  • 相关阅读:
    GoLang设计模式04
    GoLang设计模式03
    GoLang设计模式02
    GoLang设计模式01
    封装python代码,避免被轻易反编译
    openEuler 欧拉安装图形界面
    Deepin
    Debian安装PostgreSQL
    在 Linux 上使用 VirtualBox 的命令行管理界面
    Debian无法通过ssh连接
  • 原文地址:https://www.cnblogs.com/yangzhifan/p/4758213.html
Copyright © 2011-2022 走看看