plist的使用和读取
来源:互联网 发布:中秋大数据 编辑:程序博客网 时间:2024/06/06 02:14
文件目录简单说明:
- 应用程序包:包含了所有的资源文件和可执行文件
- Document:保存应用运行时生成的需要持久化的数据,iTunes 同步设备时会备份该目录。例如,游戏应用可将游戏存档保存在该目录
- tmp:保存应用运行时所需的临时数据,使用完毕后再将相应地文件从该目录删除,应用没有运行时,系统也可能会清除该目录下得所有文件。iTunes 同步设备时不会备份该目录。
- Library / Caches:保存应用运行时生成的需要持久化的数据,iTunes 同步设备时不会备份该目录。一般存储体积大,不需要备份的非重要数据。
- Library / Preference:保存应用的所有偏好设置,ios 的 Setting (设置)应用会在该目录中查找应用的设置信息。iTunes 同步设备时会备份该目录。
下面是利用字典将数据写入到.plist文件
- //
- // ViewController.m
- // plist
- //
- // Created by Rio.King on 13-9-22.
- // Copyright (c) 2013年 Rio.King. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self createPlist];
- [self readPlist];
- }
- -(void)readPlist{
- //搜索Document路径
- NSString *documents = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
- NSString *path = [documents stringByAppendingPathComponent:@"dict.plist"];
- NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
- NSLog(@"%@",dict);
- }
- -(void)createPlist{
- NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
- [dict setObject:@"chaoyuan" forKey:@"name"];
- [dict setObject:[NSNumber numberWithInt:21] forKey:@"age"];
- [dict setObject:@"www.chaoyuan.sinaapp.com" forKey:@"homepage"];
- //获取Document目录
- NSString *home = NSHomeDirectory();
- NSString *documents = [home stringByAppendingPathComponent:@"Documents"];
- NSLog(@"%@",documents);
- NSString *path = [documents stringByAppendingPathComponent:@"dict.plist"];
- //写到.plist文件中去
- [dict writeToFile:path atomically:YES];
- }
- @end
注意:
- 属性列表是一种XML格式的文件,拓展名为 plist
- 如果对象是NSString、NSDictionary、NSArray、NSData、NSNumber等基本类型,就可以使用 writeToFile:atomically:方法直接将对象写到属性列表文件中。
0 0
- plist的使用和读取
- plist的使用和读取
- plist文件的读取和NSBundle的使用
- plist文件的写入和读取
- iOS plist的存储和读取
- plist写入和读取
- 读取和写入plist文件
- 读取和写入plist文件
- iOS中使用.plist文件延迟读取的方法
- 在IOS中如何读取系统产生的plist文件和自定义的plist文件
- 在IOS中如何读取系统产生的plist文件和自定义的plist文件
- 在IOS中如何读取系统产生的plist文件和自定义的plist文件
- 最简单的本地储存数据和读取数据。plist
- ios 沙盒 plist 数据的读取和存储
- Swift - .plist文件数据的读取和存储
- ios 沙盒 plist 数据的读取和存储
- 关于pvr和plist的联合使用
- 读取存array的plist
- adb读取SD卡CID的CRC错误
- POJ 1821 Fence(DP+单调队列优化)
- 第8题:字符串长度
- Objective - C基础: 第一天 - 10.如何合理的设计一个类
- JAVA集合操作的利器:CollectionUtils
- plist的使用和读取
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- 如何取消或定制当点击GridView 的时候出现的那个黄色背景
- 冒泡排序、快速排序示例
- 编程珠玑之第三章习题1
- 集合的常用操作类CollectionUtils
- HDU 3342 -- Legal or Not(拓扑排序)
- Java学习网站大全
- VCL fro Android 实现 remote control android STB