读写 .plist 文件的代码例子
来源:互联网 发布:kali linux 路由器 编辑:程序博客网 时间:2024/06/07 22:47
http://blog.csdn.net/niitlcj/article/details/7437731
通过读写 .plist 文件,我们可以在 iPhone 里记录或调取数据,下面就是 CocoaChina 会员“pjk1129” 分享的读写 .plist 文件的代码
以name,phoneNumber,age三个字段为例。 iPhone在文本框中输入数据,获取后装入数组中,然后把数组写入.plist文件
写操作
NSString *name=[txt1 text];
NSNumber *phoneNumber=[[NSNumber alloc] initWithInt:[[txt2 text]intValue]];
NSNumber *age=[[NSNumber alloc] initWithInt:[[txt3 text]intValue]];
NSMutableArray *array=[[NSMutableArray alloc]init];
[array
[array
[array
NSArray*paths=NSSearchPathForDirectori
NSString*path=[paths
NSString *filename=[pathstringByAppendingPathCom
[arraywriteToFile:filename
[array release];
读操作
NSArray*paths=NSSearchPathForDirectori
NSString*path=[paths
NSString *filename=[pathstringByAppendingPathCom
NSMutableArray *array=[[NSMutableArray alloc]initWithContentsOfFile:filename];
txt1.text=[array objectAtIndex:0];
txt2.text=[[NSString alloc] initWithFormat:@”%d”,[[arrayobjectAtIndex:1]intValue]];
txt3.text=[[NSString alloc] initWithFormat:@”%d”,[[arrayobjectAtIndex:2]intValue]];
[array release];
- NSBundle *bundle = [NSBundle mainBundle];//取得mainBundle
- NSString *plistPath = [bundle pathForResource:@"文件名"ofType:@"plist"]; //取得文件路径
// 或可以写成
NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"文件名" ofType:@"plist"];
//读取到一个NSDictionary
NSDictionary *dictionary = [[NSDictionary alloc]initWithContentsOfFile:plistPath];
//读取到一个NSArray
NSArray *array = [[NSArray alloc]initWithContentsOfFile:plistPath];
- 读写 .plist 文件的代码例子
- 读写 .plist 文件的代码例子
- 读写 .plist 文件的代码例子
- 读写.plist文件的例子
- 最简单的plist文件读写代码
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- plist文件的读写
- Plist文件的读写
- 读写plist文件简单代码
- ios plist文件的读写
- 关于Plist文件的读写
- C++编程迷宫
- 安装ubuntu14.04
- PHP为什么会被认为是草根语言?
- 最大公约数
- 文章标题
- 读写 .plist 文件的代码例子
- 字符串分离方法
- 5 分钟上手 ECharts(echart官网转载)
- TEST
- 整流滤波电路图绘制后,元件自动编号
- 基础算法-插入排序
- RSA 数字签名 免密码登录
- 我是一只新晋程序狗
- ubuntu12.04安装nginx