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

  • 相关阅读:
    m_Orchestrate learning system---三十一、模板和需求的关系
    你如何破解后安装PS cs6
    STL 源代码分析 算法 stl_algo.h -- pre_permutation
    霸气侧漏HTML5--之--canvas(1) api + 弹球例子
    hello nodejs
    整洁的正则表达式教程,这很容易理解
    基于Gsoap 的ONVIF C++ 库
    一个常见的错误时编写代码
    IT只忍者龟Photoshop简单人像的头发抠图过程
    彩色图像--色彩空间 HSI(HSL)、HSV(HSB)
  • 原文地址:https://www.cnblogs.com/ketmales/p/2842555.html
Copyright © 2011-2022 走看看