zoukankan      html  css  js  c++  java
  • read from plist file

    Read from .plist File

    An Example

    tryplist.plist
    Key Type Value
    Root Dictionary (2 items)
        subroot1 Dictionary (3 items)
            name1 String this is string 1
            name2 Number 1.5
            name3 String this is string a
        subroot2 Dictionary (3 items)
            name1 String this is string 2
            name2 Number 2.5
            name3 String this is string b

    Code

    create dictionary from file

    // get file path
    NSString *plistpath = [[NSBundle mainBundle] pathForResource: @"tryplist" ofType: @"plist"];
    // create dictionary from file
    NSDictionary *plistDictionary = [NSDictionary dictionaryWithContentsOfURL: [NSURL fileURLWithPath: plistpath]];

    get data from dictionary

    // get subroot1 dictionary
    NSDictionary *subroot1Dictionary = [plistDictionary objectForKey: @"subroot1"];
    // get name1 of subroot1
    NSString *subroot1name1 = [subroot1Dictionary objectForKey: @"name1"];
    NSLog(@"%@", subroot1name1);
    // get name2 of subroot1
    float subroot1name2 = [[subroot1Dictionary objectForKey: @"name2"] floatValue];
    NSLog(@"%f", subroot1name2);
    // get name3 of subroot1
    NSString *subroot1name3 = [subroot1Dictionary objectForKey: @"name3"];
    NSLog(@"%@", subroot1name3);
    // get subroot2 dictionary
    NSDictionary *subroot2Dictionary = [plistDictionary objectForKey: @"subroot2"];
    // get name1 of subroot2
    NSString *subroot2name1 = [subroot2Dictionary objectForKey: @"name1"];
    NSLog(@"%@", subroot2name1);
    // get name2 of subroot2
    float subroot2name2 = [[subroot2Dictionary objectForKey: @"name2"] floatValue];
    NSLog(@"%f", subroot2name2);
    // get name3 of subroot2
    NSString *subroot2name3 = [subroot2Dictionary objectForKey: @"name3"];
    NSLog(@"%@", subroot2name3);

    Output

    2013-01-02 23:11:28.354 ketmales[6290:c07] this is string 1
    2013-01-02 23:11:28.355 ketmales[6290:c07] 1.500000
    2013-01-02 23:11:28.355 ketmales[6290:c07] this is string a
    2013-01-02 23:11:28.356 ketmales[6290:c07] this is string 2
    2013-01-02 23:11:28.356 ketmales[6290:c07] 2.500000
    2013-01-02 23:11:28.356 ketmales[6290:c07] this is sting b

  • 相关阅读:
    D django 用户认证系统
    vim 跳到指定行
    django 的auth.authenticate返回为None
    git fetch 的简单用法:更新远程代码到本地仓库
    sql语句查询出表里符合条件的第二条记录的方法
    你一定喜欢看的 Webpack 2.× 入门实战
    webpack 从入门到工程实践
    入门Webpack,看这篇就够了
    教程
    常用浏览器如何设置代理服务器上网(图文教程)
  • 原文地址:https://www.cnblogs.com/ketmales/p/2842555.html
Copyright © 2011-2022 走看看