plist的读写存代码示例
| 01 | - (void)viewDidLoad { |
| 02 |
| 03 | //读取plist |
| 04 | NSString *path = [[NSBundle mainBundle] pathForResource:@”demo” ofType:@”plist”]; |
| 05 | NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; |
| 06 | NSLog(@”%d”,[data count]); |
| 07 |
| 08 | //添加一项内容 |
| 09 | [data setObject:@"content" forKey:@"item4"]; |
| 10 |
| 11 | //获取应用程序沙盒的Documents目录 |
| 12 | NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); |
| 13 | path = [paths objectAtIndex:0]; |
| 14 |
| 15 | //得到完整的文件名 |
| 16 | NSString *filename=[path stringByAppendingPathComponent:@"test.plist"]; |
| 17 |
| 18 | [data writeToFile:filename atomically:YES]; |
| 19 | [data release]; |
| 20 | [super viewDidLoad]; |
| 21 | } |
浙公网安备 33010602011771号