从文档目录而不是 Bundle 获取 plist
我试图指向文档目录而不是捆绑包,我有以下代码:
- (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];
我的问题是在上面的示例中在哪里插入此指针?
I'm trying to point to the documents directory instead of the Bundle, I have the following code:
- (id)initWithLibraryName:(NSString *)libraryName {
if (self = [super init]) {
libraryPlist = libraryName;
libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:libraryPlist ofType:@"plist"]];
I know I need to point the app to the documents directory using the following:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
My question is where do I insert this pointer in the above example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也是等价的:
只不过如果文件不存在,bundle 调用将返回 nil。您可以在 NSFileManager 中使用
fileExistsAtPath:
来检查文件是否存在。Is equivalent too:
Except that the bundle call will return nil if the file does not exist. You can use
fileExistsAtPath:
in NSFileManager to check if a file exists.