20150623_OC之属性列表文件plist
2015-07-03 21:04
369 查看
plist文件的结构及操作:
// // ParsePlist.h // IOS150623_ObjectiveC_Plist文件1 // // Created by PengJunlong on 15/6/23. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import <Foundation/Foundation.h> @interface ParsePlist : NSObject - (void)parseFile:(NSDictionary *)dic; @end
// // ParsePlist.m // IOS150623_ObjectiveC_Plist文件1 // // Created by PengJunlong on 15/6/23. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import "ParsePlist.h" @implementation ParsePlist - (void)parseFile:(NSDictionary *)dic { NSDictionary *dic1 = [dic objectForKey:@"frames"]; char keyName[20]; char propertyName[20]; printf("输入:"); scanf("%s%s",keyName,propertyName); NSDictionary *subOfDic1 = [dic1 objectForKey:[NSString stringWithUTF8String:keyName]]; if (subOfDic1) { NSString *valueStr = [subOfDic1 objectForKey:[NSString stringWithUTF8String:propertyName]]; NSLog(@"subOFDic1 = %@",valueStr); } } @end
// // main.m // IOS150623_ObjectiveC_Plist文件1 // // Created by PengJunlong on 15/6/23. // Copyright (c) 2015年 Peng Junlong. All rights reserved. // #import <Foundation/Foundation.h> #import "ParsePlist.h" //*************************** //* plist文件 * //*************************** //plist(properties list)文件的只有一个根节点,根只能是数组(NSArray)或者是字典(NSDictionary),不能为其他的类型,plist文件里可以直接进行添加删除 //plist中存储的对象:NSArray, NSDcitionary, NSDate, NSData, NSNumber, NSString, Boolean int main(int argc, const char * argv[]) { @autoreleasepool { NSArray *array = [[NSArray alloc] initWithObjects:@"one",@"two",[NSNumber numberWithInt:23],[NSDate date], nil]; //在指定目录下没有对应的plist文件,会自动创建该文件 BOOL ret = [array writeToFile:@"/Users/qianfeng/Desktop/test/dic3/app.plist" atomically:YES]; if (ret) { NSLog(@"写入成功"); } else { NSLog(@"写入失败"); } NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"one",@"2",@"two",[NSNumber numberWithInt:22],@"num",[@"IOS" dataUsingEncoding:NSUTF8StringEncoding],@"ios",[NSDate date],@"date",array,@"array", nil]; BOOL ret1 = [dictionary writeToFile:@"/Users/qianfeng/Desktop/test/dic3/array.plist" atomically:YES]; if (ret1) { NSLog(@"写入成功"); } else { NSLog(@"写入失败"); } //只能读取plist文件中根节点是Dictionary NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:@"/Users/qianfeng/Public/ExerciseProject/IOS150623_ObjectiveC_Plist文件1/apple.plist"]; NSLog(@"dic = %@",dic); //只能读取plist文件中根节点是Array NSArray *arr = [NSArray arrayWithContentsOfFile:@"/Users/qianfeng/Desktop/test/dic3/app.plist"]; NSLog(@"array = %@",arr); //--------------解析plist文件------------- NSDictionary *dict1 = [NSDictionary dictionaryWithContentsOfFile:@"/Users/qianfeng/Public/ExerciseProject/IOS150623_ObjectiveC_Plist文件1/qfile.plist"]; ParsePlist *parse = [[ParsePlist alloc] init]; [parse parseFile:dict1]; } return 0; }
相关文章推荐
- Java中 equals 和 == 区别
- C++重载覆盖和隐藏,虚函数与纯虚函数
- Deep Learning for Nature Language Processing---第四讲(上)
- ios监听某些事件的方法
- 采集
- C语言qsort C++的sort
- 我的Android第一步:开发环境搭建ADT-Bundle及Hello World
- NuttX 启动流程
- 二维数据搜索(算法)
- 常用的JS插件介绍:3、masonry——瀑布流(结合requirejs、art-template、infinite-scroll)
- 20150623_OC之时间NSDate与NSDateFormatter
- mysql事务
- java总结(之七)--Java I/O系统
- 面试10大算法汇总
- Asp.net Vnext 调试源码
- 上传、下载
- 编译器是如何判断一个函数的结束的???程序
- 安装go 环境
- 常用的JS插件介绍:2、ajaxFileUpload——异步上传
- linux命令