如何在Cocoa应用程序的MainBundle中以编程方式创建属性列表文件。我知道如何读取和写入plist文件的内容。
答案 0 :(得分:0)
我将数组写入plist并使用类似下面的代码读出它。可能有用。
- (NSString *)offlineCachePath {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSCachesDirectory, NSUserDomainMask, YES);
NSString *cache = [paths objectAtIndex:0];
NSString *path = [cache stringByAppendingPathComponent:@"NameOfApp"];
// Check if the path exists, otherwise create it
if (![fileManager fileExistsAtPath:path]) {
[fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
}
return path;
}
- (NSString *)cachedStuffPath {
NSString *cachedStuffPath = [[self offlineCachePath] stringByAppendingPathComponent:@"NameOfFile.plist"];
return cachedStuffPath;
}
- (NSMutableArray *)getCachedStuff {
return [[NSArray arrayWithContentsOfFile:[self cachedStuffPath]] mutableCopy];
}
- (void)cacheStuff:(NSMutableArray *)stuff {
[stuff writeToFile:[self cachedStuffPath] atomically:YES];
}