• ios plist 读取


    - (void)viewDidLoad

    {

        [superviewDidLoad];

       // Do any additional setup after loading the view, typically from a nib.

     // [self setupArray];

        

        //读取plist

        NSBundle *bundle = [NSBundlemainBundle];

        // 设置资源文件名称为Property List,资源类型为plist

        NSString *path = [bundle pathForResource:@"StateCapital"ofType:@"plist"];

        // plist中配置了一个NSDictionary字典,字典keyStateCapital

        NSMutableDictionary *dict = [[[NSDictionaryalloc]initWithContentsOfFile:path] objectForKey:@"StateCapital"];

        //初始化dataSource

        dataSource = [dict objectForKey:@"States"];

        //初始化states

        states = [[NSMutableDictionaryalloc]initWithObjects:[dict objectForKey:@"Capitals"] forKeys:dataSource];

    }

    - (void)setupArray

    {

        states = [[NSMutableDictionaryalloc]init];

        [statessetObject:@"Lansing"forKey:@"Michigan"];

        [statessetObject:@"Sacremento"forKey:@"California"];

        [statessetObject:@"Albany"forKey:@"New York"];

        [statessetObject:@"Phoenix"forKey:@"Arizona"];

        [statessetObject:@"Tulsa"forKey:@"Oklahoma"];

        

        dataSource = [statesallKeys];

    }

     

    plist:  

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">

    <plist version="1.0">

    <dict>

    <key>StateCapital</key>

    <dict>

    <key>States</key>

            <array>

                <string>Michigan</string>

                <string>California</string>

                <string>New York</string>

                <string>Arizona</string>

                <string>Oklahoma</string>

            </array>

            <key>Capitals</key>

            <array>

                <string>Lansing</string>

                <string>Sacremento</string>

                <string>Albany</string>

                <string>Phoenix</string>

                <string>Tulsa</string>

            </array>            

    </dict>

    </dict>

    </plist>

     

    //用plist取代setupArray

     

     

  • 相关阅读:
    解决Windows 10每次重启默认浏览器都被重置为IE的一个办法
    使用cookie登录百度网盘账号
    【C++ Primer | 14】重载运算
    Visual Studio Code 快捷键的使用
    【C++ Primer | 8】IO库
    Git push常见用法
    Git 基础
    Git连接GitHub仓库详解
    ceph关于rpm包构建的教程
    monitor综合
  • 原文地址:https://www.cnblogs.com/frank2008syj/p/2861225.html
Copyright © 2020-2023  润新知