zoukankan      html  css  js  c++  java
  • 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

     

     

  • 相关阅读:
    echarts 变量a、b、c、d的含义
    JS实现字符点点loading效果
    ES6的异步 async promise
    ES6中Promise封装ajax的写法
    ES6 set数据结构举例
    notepad++ 正则替换 字符串开始 字符串结束
    php去除bom
    jquery-ui Datepicker 创建 销毁
    Vue-cli3 WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB)
    XManager product key
  • 原文地址:https://www.cnblogs.com/frank2008syj/p/2861225.html
Copyright © 2011-2022 走看看