如何在iPhone中的plist中写入多个数组?

发布于 2024-09-17 18:21:47 字数 127 浏览 4 评论 0原文

我的应用程序中有十个数组。我想将这些数组值写入(文档目录)plist。是否可以将 10 个数组放入一个 plist 中?否则我将为每个数组创建单独的 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.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独行侠 2024-09-24 18:21:47

做你想做的一切是很容易的。

如何创建应用程序文档目录的文件路径:

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];

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"];

How to read it in:

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

How to write it out:

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:array1 forKey:@"array1"];
[dictionary setObject:array2 forKey:@"array2"];
... etc ...
[dictionary writeToFile:plistPath atomically:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文