如何写的plist多个阵列的iPhone? [英] How to write multiple arrays in plist in iPhone?

查看:157
本文介绍了如何写的plist多个阵列的iPhone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序10阵列。我想这些数组值写入(文件S目录)的plist。有可能把10阵列成一的plist?.ELSE我会为每个阵列单独的plist。哪一个是可以实现我的应用程序?请指导我,给一些示例的链接。

I have ten arrays in my application. I want to write those array values into the (document s directory)plist. Is possible to put 10 arrays into the one plist?.Else i will create separate plist for each arrays. Which one is possible to implement my application?. Please guide me and give some sample links.

感谢

推荐答案

这是pretty容易做所有你想要的。

It's pretty easy to do all you want.

如何使一个文件路径,您的应用程序文档目录:

How to make a file path to your applications document directory:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* plistpath = [[paths objectAtIndex:0] stringByAppendingPathComponent: @"myplist.plist"];

如何阅读:

NSDictionary *dictionary;
dictionary = [NSDictionary dictionaryWithContentsOfFile:plistpath];
NSArray* array1 = [dictonary objectForKey: @"array1"];
NSArray* array2 = [dictonary objectForKey: @"array2"];
... etc ...

如何写出来:

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:array1 forKey:@"array1"];
[dictionary setObject:array2 forKey:@"array2"];
... etc ...
[dictionary writeToFile:plistPath atomically:NO];

这篇关于如何写的plist多个阵列的iPhone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆