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

标签 iphone arrays plist

我的应用程序中有十个数组。我想将这些数组值写入(文档目录)plist。是否可以将 10 个数组放入一个 plist 中?否则我将为每个数组创建单独的 plist。哪一个可以实现我的应用程序?请指导我并提供一些示例链接。

谢谢

最佳答案

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

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

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

关于iphone - 如何在iPhone中的plist中写入多个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3636524/

相关文章:

ios - WatchKit 的用户定义设置

iphone - 为什么我的 UIToolbar 出现在奇怪的位置?

iPhone App 在 iOS 4.1 下消亡。没有代码更改

iphone - 带日期(参数)的 XML 解析

mysql - PHP 关联数组 : special character?

java - 删除最小值后如何基于 "heapify"数组的最小堆?

iOS浅亚麻布背景?

javascript - 将带有 json_encode 的 php 数组传递给 js 处理程序时出错

ios - 如何在 Swift 中使用 plist 中的值而不将它们作为 AnyObject 出现?

iphone - CFBundleURLTypes 不变