0

I have to create a property list from NSMutableArray programmatically under a valid path, I mean under resource folder. So that I can access it whenever there is need. Please help me if somebody knows about it. Also I need to convert that plist into NSMutableArray so I can use that value. I have searched and tried to do that but have not successful. Thanx in advance !

4

1 回答 1

1

整个 App 包对于 iOS 应用程序是只读的,因此您不能在运行时添加任何资源。例如,您可以为此目的使用 Library/Caches 文件夹。参见URLsForDirectory:inDomains:查找该目录的路径。

例如:

// Path to a plist file in Caches directory:
NSURL *cacheDir = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *plistFile = [cacheDir URLByAppendingPathComponent:@"myresource.plist"];

// write array to plist file:
[myArray writeToURL:plistFile atomically:NO];

// read array from plist file and make it mutable:
NSMutableArray *secondArray =  [[NSArray arrayWithContentsOfURL:plistFile] mutableCopy];
于 2012-08-11T09:44:18.353 回答