我的应用程序中有十个数组。我想将这些数组值写入(文档目录)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/