[英]getting plist from documents directory instead of Bundle
我试图指向文档目录而不是Bundle,我有以下代码:
- (id)initWithLibraryName:(NSString *)libraryName {
if (self = [super init]) {
libraryPlist = libraryName;
libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:libraryPlist ofType:@"plist"]];
我知道我需要使用以下命令将应用程序指向文档目录:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
我的问题是在上面的示例中该指针应插入哪里?
[[NSBundle mainBundle] pathForResource:libraryPlist ofType:@"plist"];
也是等效的:
[documentsDirectory stringByAppendingPathComponent:[libraryPlist stringByAppendingPathExtension:@"plist"]];
如果文件不存在,则bundle调用将返回nil。 您可以在NSFileManager中使用fileExistsAtPath:
来检查文件是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.