zoukankan      html  css  js  c++  java
  • IOS对plist配置文件的读写操作

    读取:
    ---------------------------------------------------------------

    //首先读取studentInfo.plist中的数据
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"customInfo" ofType:@"plist"];
    NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
        
    //将学生信息填入视图
    NSDictionary *tmpInfo = [dictionary objectForKey: @"Student"];
    self.stuName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
    self.stuSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];
    self.stuNum.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Num"]];
        
    //将导师信息写入视图
    tmpInfo = [dictionary objectForKey: @"Mentor"];
    self.mtName.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Name"]];
    self.mtSex.text = [NSString stringWithFormat:@"%@", [tmpInfo objectForKey: @"Sex"]];


    全新写入:
    ---------------------------------------------------------------
    NSMutableDictionary *dictplist = [[NSMutableDictionary alloc ] init];
    //定义第一个插件的属性
    NSMutableDictionary *plugin1 = [[NSMutableDictionary alloc]init];
    [plugin1 setObject:@"张三" forKey:@"name1"];
    [plugin1 setObject:@"李四" forKey:@"name2"];
    //定义第二个插件的属性
    NSMutableDictionary *plugin2 = [[NSMutableDictionary alloc]init];
    [plugin2 setObject:@"王五" forKey:@"name1"];
    [plugin2 setObject:@"赵斌" forKey:@"name2"];
    //设置属性值
    [dictplist setObject:plugin1 forKey:@"初一班"];
    [dictplist setObject:plugin2 forKey:@"初二班"];
    //写入文件
    [dictplist writeToFile:plistPath atomically:YES];

     

    //修改某一配置项。

    //载入配置文件。   
        NSString* plistPath = [NSString stringWithFormat:@"%@/letters.plist",[[Globals getResourceManager] getResPath]];
            
        NSMutableDictionary* dicWrite = [[[NSMutableDictionary alloc] initWithContentsOfFile:plistPath] mutableCopy];
        NSMutableDictionary* dicWLetter = [dicWrite objectForKey:letter];
        NSString* v = alertView.tag == 1 ? @"1" : @"0";
        [dicWLetter setValue:v forKey:@"isOk"];
        [dicWrite setValue:dicWLetter forKey:letter];
        
        [dicWrite writeToFile:plistPath atomically:YES];
        [dicWrite release];
        dicWrite = nil;

     

  • 相关阅读:
    77777 77777(2) WriteUp 绕waf技巧学习
    简单sql注入学到的延时盲注新式攻击
    代码审计 => 74cms_v3.5.1.20141128 一系列漏洞
    mysql注入新姿势(数字与字符编码注入) hex,conv
    Netty 3升级Netty4实践
    微信小程序获取用户openid,头像昵称信息,后台java代码
    转:JSP 分页显示数据 (Oracle)
    从数据库提取数据通过jstl显示在jsp页面上
    转:微信生成二维码java
    转:微信开发获取地理位置实例(java,非常详细,附工程源码)
  • 原文地址:https://www.cnblogs.com/mrhgw/p/2579572.html
Copyright © 2011-2022 走看看